Browse Source

+ f2b_csocket_rtimeout()

master
Alex 'AdUser' Z 8 years ago
parent
commit
77b136796a
  1. 12
      src/csocket.c
  2. 2
      src/csocket.h

12
src/csocket.c

@ -96,6 +96,18 @@ f2b_csocket_disconnect(int sock, const char *cpath) {
return;
}
void
f2b_csocket_rtimeout(int sock, float timeout) {
int ret = 0;
struct timeval tv;
tv.tv_sec = (int) timeout;
tv.tv_usec = (int) ((timeout - tv.tv_sec) * 1000000);
ret = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *) &tv, sizeof(struct timeval));
if (ret == 0)
return;
f2b_log_msg(log_warn, "can't set recv timeout for csocket: %s", strerror(errno));
}
/**
* @brief Recieve and unpack control message
* @param csock Opened socket fd

2
src/csocket.h

@ -17,6 +17,8 @@ void f2b_csocket_destroy(int csock, const char *path);
int f2b_csocket_connect(const char *spath, const char *cpath);
void f2b_csocket_disconnect(int sock, const char *cpath);
void f2b_csocket_rtimeout(int sock, float timeout);
int f2b_csocket_poll(int csock, void (*cb)(const f2b_cmsg_t *cmsg, char *res, size_t ressize));
int f2b_csocket_send(int csock, f2b_cmsg_t *cmsg, struct sockaddr_storage *addr, socklen_t *socklen);
int f2b_csocket_recv(int csock, f2b_cmsg_t *cmsg, struct sockaddr_storage *addr, socklen_t *socklen);

Loading…
Cancel
Save