rllib  1
Macros | Functions
rlsocket.cpp File Reference
#include "rldefine.h"
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <io.h>
#include <direct.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "rlsocket.h"
#include "rlwthread.h"
#include "rlcutil.h"
Include dependency graph for rlsocket.cpp:

Go to the source code of this file.

Macros

#define WTREAD_GNUC5   ( __GNUC__ * 1000 ) + __GNUC_MINOR__
 
#define MSG_NOSIGNAL   0
 
#define MSG_NOSIGNAL   0
 

Functions

void WSAAPI freeaddrinfo (struct addrinfo *)
 
int WSAAPI getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **)
 
int WSAAPI getnameinfo (const struct sockaddr *, socklen_t, char *, DWORD, char *, DWORD, int)
 
int rlwsa ()
 
int rlScoketWrite (int *socket, const void *buf, int len)
 

Macro Definition Documentation

◆ MSG_NOSIGNAL [1/2]

#define MSG_NOSIGNAL   0

Definition at line 53 of file rlsocket.cpp.

◆ MSG_NOSIGNAL [2/2]

#define MSG_NOSIGNAL   0

Definition at line 53 of file rlsocket.cpp.

◆ WTREAD_GNUC5

#define WTREAD_GNUC5   ( __GNUC__ * 1000 ) + __GNUC_MINOR__

Definition at line 30 of file rlsocket.cpp.

Function Documentation

◆ freeaddrinfo()

void WSAAPI freeaddrinfo ( struct addrinfo *  )

◆ getaddrinfo()

int WSAAPI getaddrinfo ( const char *  ,
const char *  ,
const struct addrinfo *  ,
struct addrinfo **   
)

◆ getnameinfo()

int WSAAPI getnameinfo ( const struct sockaddr *  ,
socklen_t  ,
char *  ,
DWORD  ,
char *  ,
DWORD  ,
int   
)

◆ 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 }