aboutsummaryrefslogtreecommitdiffstats
path: root/sock.h
blob: c3c0428ef6cde256ce3f0fa98993f00e543b19f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <errno.h>
#include <fcntl.h>

#ifndef _WIN32
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#define sock_make_nonblocking(fd) fcntl(fd, F_SETFL, O_NONBLOCK)
#define sock_make_blocking(fd) fcntl(fd, F_SETFL, 0)
#define sockerr_again() (errno == EINPROGRESS || errno == EINTR)
#ifndef EVENTS_LIBEVENT
#define closesocket(a) close(a)
#endif
#else
# include <winsock2.h>
# ifndef _MSC_VER
#  include <ws2tcpip.h>
# endif
# if !defined(BITLBEE_CORE) && defined(_MSC_VER)
#   pragma comment(lib,"bitlbee.lib")
# endif
# include <io.h>
# define read(a,b,c) recv(a,b,c,0)
# define write(a,b,c) send(a,b,c,0)
# define umask _umask
# define mode_t int
# define sock_make_nonblocking(fd) { int non_block = 1; ioctlsocket(fd, FIONBIO, &non_block); }
# define sock_make_blocking(fd) { int non_block = 0; ioctlsocket(fd, FIONBIO, &non_block); }
# define sockerr_again() (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == WSAEWOULDBLOCK)
# define ETIMEDOUT WSAETIMEDOUT
# define sleep(a) Sleep(a*1000)
#endif