source: sock.h @ 85cf37f

Last change on this file since 85cf37f was 3f199fc, checked in by Wilmer van der Gaast <wilmer@…>, at 2006-05-13T23:28:31Z

Added a closesocket() that properly removes event handlers before closing a socket.

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include <errno.h>
2#include <fcntl.h>
3
4/* To cut down on the ifdef stuff a little bit in other places */
5#ifdef IPV6
6#define AF_INETx AF_INET6
7#else
8#define AF_INETx AF_INET
9#endif
10
11#ifndef _WIN32
12#include <unistd.h>
13#include <sys/socket.h>
14#include <netinet/in.h>
15#include <arpa/inet.h>
16#include <netdb.h>
17#define sock_make_nonblocking(fd) fcntl(fd, F_SETFL, O_NONBLOCK)
18#define sock_make_blocking(fd) fcntl(fd, F_SETFL, 0)
19#define sockerr_again() (errno == EINPROGRESS || errno == EINTR)
20#ifndef EVENTS_LIBEVENT
21#define closesocket(a) close(a)
22#endif
23#else
24# include <winsock2.h>
25# ifndef _MSC_VER
26#  include <ws2tcpip.h>
27# endif
28# if !defined(BITLBEE_CORE) && defined(_MSC_VER)
29#   pragma comment(lib,"bitlbee.lib")
30# endif
31# include <io.h>
32# define read(a,b,c) recv(a,b,c,0)
33# define write(a,b,c) send(a,b,c,0)
34# define umask _umask
35# define mode_t int
36# define sock_make_nonblocking(fd) { int non_block = 1; ioctlsocket(fd, FIONBIO, &non_block); }
37# define sock_make_blocking(fd) { int non_block = 0; ioctlsocket(fd, FIONBIO, &non_block); }
38# define sockerr_again() (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == WSAEWOULDBLOCK)
39# define ETIMEDOUT WSAETIMEDOUT
40# define sleep(a) Sleep(a*1000)
41#endif
Note: See TracBrowser for help on using the repository browser.