rllib  1
Classes | Macros | Functions
rlsocket.h File Reference
#include "rldefine.h"
#include "rlstring.h"
#include <winsock2.h>
#include <windows.h>
#include <io.h>
#include <direct.h>
Include dependency graph for rlsocket.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  rlSocket
 

Macros

#define wsa   rlwsa
 

Functions

int rlwsa ()
 
int rlScoketWrite (int *socket, const void *buf, int len)
 

Macro Definition Documentation

◆ wsa

#define wsa   rlwsa
you have to call this function before you use any sockets
(at least under windows)

Definition at line 39 of file rlsocket.h.

Function Documentation

◆ rlScoketWrite()

int rlScoketWrite ( int *  socket,
const void *  buf,
int  len 
)

Definition at line 95 of file rlsocket.cpp.

96 {
97  int ret,bytes_left,first_byte;
98  const char *cbuf;
99 
100  if(socket == NULL) return -1;
101  if(*socket == -1) return -1;
102  cbuf = (char *) buf;
103  bytes_left = len;
104  first_byte = 0;
105 
106  while(bytes_left > 0)
107  {
108  ret = send(*socket,&cbuf[first_byte],bytes_left,MSG_NOSIGNAL);
109  if(ret <= 0)
110  {
111  //disconnect();
112  if(*socket != -1)
113  {
114 #ifdef RLWIN32
115  closesocket(*socket);
116 #else
117  close(*socket);
118 #endif
119  }
120  *socket = -1;
121  return -1;
122  }
123  bytes_left -= ret;
124  first_byte += ret;
125  }
126 
127  return first_byte;
128 }
#define MSG_NOSIGNAL
Definition: rlsocket.cpp:53

◆ rlwsa()

int rlwsa ( )

Definition at line 68 of file rlsocket.cpp.

69 {
70 #ifdef RLWIN32
71  static int first = 1;
72  WORD wVersionRequested;
73  WSADATA wsadata;
74  int err;
75 
76  if(first == 1)
77  {
78 #ifdef IS_OLD_MSVCPP
79  wVersionRequested = MAKEWORD(1,1);
80 #else
81  wVersionRequested = MAKEWORD(2,0);
82 #endif
83  err = WSAStartup(wVersionRequested, &wsadata);
84  if(err != 0)
85  {
86  ::printf("Startup error=%d on windows\n",err);
87  exit(0);
88  }
89  first = 0;
90  }
91 #endif
92  return 0;
93 }