Browse Source

Provide a write socket function

master
Con Kolivas 11 years ago
parent
commit
8222166257
  1. 26
      src/libckpool.c
  2. 1
      src/libckpool.h

26
src/libckpool.c

@ -388,6 +388,32 @@ out:
return sockd;
}
int write_socket(int fd, const void *buf, size_t nbyte)
{
struct timeval tv_timeout = {1, 0};
fd_set writefds;
int ret;
retry:
FD_ZERO(&writefds);
FD_SET(fd, &writefds);
ret = select(fd + 1, NULL, &writefds, NULL, &tv_timeout);
if (ret < 0 && interrupted())
goto retry;
if (ret < 1) {
if (!ret)
LOGNOTICE("Select timed out in write_socket");
else
LOGNOTICE("Select failed in write_socket with errno %d", errno);
goto out;
}
ret = write(fd, buf, nbyte);
if (ret < 0)
LOGWARNING("Failed to write in write_socket");
out:
return ret;
}
/* Align a size_t to 4 byte boundaries for fussy arches */
void align_len(size_t *len)
{

1
src/libckpool.h

@ -138,6 +138,7 @@ void keep_sockalive(int fd);
void noblock_socket(int fd);
void block_socket(int fd);
int connect_socket(char *url, char *port);
int write_socket(int fd, const void *buf, size_t nbyte);
void align_len(size_t *len);
void realloc_strcat(char **ptr, const char *s);

Loading…
Cancel
Save