2 #define ioctl ioctlsocket 4 #define closesock myclosesocket 9 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 10 #define EWOULDBLOCK WSAEWOULDBLOCK 11 #define ECONNREFUSED WSAECONNREFUSED 12 #define HOST_NOT_FOUND WSAHOST_NOT_FOUND 13 #define NO_DATA WSANO_DATA 24 #define closesock close 25 #define readsock(a,b,c,d) read(a,b,c) 27 #if defined(__linux__) && !defined (darwin) 28 #define writesock(a,b,c,d) send(a,b,c,MSG_NOSIGNAL) 30 #define writesock(a,b,c,d) write(a,b,c) 33 #include <sys/socket.h> 35 #include <netinet/in.h> 36 #include <netinet/tcp.h> 38 #include <sys/ioctl.h> 43 #include <sys/types.h> 50 #define ushort unsigned short 51 #define TCP_RCV_BUF_SIZE 16384 52 #define TCP_SND_BUF_SIZE 16384 58 WORD wVersionRequested;
61 static int sock_init_done = 0;
63 if(sock_init_done)
return(1);
64 wVersionRequested = MAKEWORD( 2, 0 );
65 err = WSAStartup( wVersionRequested, &wsaData );
78 if ( LOBYTE( wsaData.wVersion ) != 2 ||
79 HIBYTE( wsaData.wVersion ) != 0 )
88 int myclosesocket(
int path)
91 code = WSAGetLastError();
92 ret = closesocket(path);
93 WSASetLastError(code);
103 struct sockaddr_in sockname;
104 struct hostent *host;
105 int path, val, ret_code, ret;
110 if( (host = gethostbyname(node)) == (
struct hostent *)0 )
115 if( (path = socket(AF_INET, SOCK_STREAM, 0)) == -1 )
123 if ((ret_code = setsockopt(path, IPPROTO_TCP, TCP_NODELAY,
124 (
char*)&val,
sizeof(val))) == -1 )
127 printf(
"Couln't set TCP_NODELAY\n");
134 if ((ret_code = setsockopt(path, SOL_SOCKET, SO_SNDBUF,
135 (
char*)&val,
sizeof(val))) == -1 )
138 printf(
"Couln't set SO_SNDBUF\n");
145 if ((ret_code = setsockopt(path, SOL_SOCKET, SO_RCVBUF,
146 (
char*)&val,
sizeof(val))) == -1 )
149 printf(
"Couln't set SO_RCVBUF\n");
155 #if defined(__linux__) && !defined (darwin) 157 if ((ret_code = setsockopt(path, IPPROTO_TCP, TCP_SYNCNT,
158 (
char*)&val,
sizeof(val))) == -1 )
161 printf(
"Couln't set TCP_SYNCNT\n");
166 sockname.sin_family = PF_INET;
167 sockname.sin_addr = *((
struct in_addr *) host->h_addr);
168 sockname.sin_port = htons((
ushort) port);
169 while((ret = connect(path, (
struct sockaddr*)&sockname,
sizeof(sockname))) == -1 )
186 wrote =
writesock( path, buffer, size, 0 );
#define writesock(a, b, c, d)
int tcp_write(int path, char *buffer, int size)
int tcp_open_client(char *node, int port)