KrisLibrary  1.0.0
socketutils.h
1 #ifndef UTILS_SOCKET_UTILS_H
2 #define UTILS_SOCKET_UTILS_H
3 
4 #ifndef _WIN32
5 #include <sys/socket.h>
6 typedef int SOCKET;
7 const static int INVALID_SOCKET = -1;
8 #else
9 #include <WinSock2.h>
10 #endif
11 
18 bool ParseAddr(const char* addr,char* protocol,char* host,int& port);
19 
22 SOCKET Connect(const char* addr);
23 
29 SOCKET Bind(const char* addr,bool block=true);
30 
33 SOCKET Accept(SOCKET sockfd);
34 
37 SOCKET Accept(SOCKET sockfd,double timeout);
38 
40 void SetNonblock(SOCKET sockfd,bool enabled=true);
41 
43 void CloseSocket(SOCKET sockfd);
44 
46 void SetNodelay(SOCKET sockfd,bool enabled=true);
47 
49 bool ReadAvailable(SOCKET socketfd);
50 
52 bool WriteAvailable(SOCKET socketfd);
53 
55 bool HasException(SOCKET socketfd);
56 
57 #endif
58