Browse Source

Add socket tests to libckpool

master
Con Kolivas 11 years ago
parent
commit
484fe86355
  1. 16
      src/libckpool.c
  2. 22
      src/libckpool.h

16
src/libckpool.c

@ -16,11 +16,9 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <errno.h>
#include "ckpool.h" #include "ckpool.h"
#include "libckpool.h" #include "libckpool.h"
@ -41,6 +39,20 @@ void keep_sockalive(int fd)
setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &tcp_keepintvl, sizeof(tcp_keepintvl)); setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &tcp_keepintvl, sizeof(tcp_keepintvl));
} }
void noblock_socket(int fd)
{
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, O_NONBLOCK | flags);
}
void block_socket(int fd)
{
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
}
/* Align a size_t to 4 byte boundaries for fussy arches */ /* Align a size_t to 4 byte boundaries for fussy arches */
void align_len(size_t *len) void align_len(size_t *len)
{ {

22
src/libckpool.h

@ -13,8 +13,30 @@
#define LIBCKPOOL_H #define LIBCKPOOL_H
#include <stdbool.h> #include <stdbool.h>
#include <errno.h>
static inline bool sock_connecting(void)
{
return errno == EINPROGRESS;
}
static inline bool sock_blocks(void)
{
return (errno == EAGAIN || errno == EWOULDBLOCK);
}
static inline bool sock_timeout(void)
{
return (errno == ETIMEDOUT);
}
static inline bool interrupted(void)
{
return (errno == EINTR);
}
void keep_sockalive(int fd); void keep_sockalive(int fd);
void noblock_socket(int fd);
void block_socket(int fd);
bool sock_connecting(void);
void align_len(size_t *len); void align_len(size_t *len);
void __bin2hex(uchar *s, const uchar *p, size_t len); void __bin2hex(uchar *s, const uchar *p, size_t len);
void *bin2hex(const uchar *p, size_t len); void *bin2hex(const uchar *p, size_t len);

Loading…
Cancel
Save