rllib  1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
rlsocket.h
Go to the documentation of this file.
1 /***************************************************************************
2  rlsocket.h - description
3  -------------------
4  begin : Tue Jan 02 2001
5  copyright : (C) 2001 by R. Lehrig
6  email : lehrig@t-online.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
13  * published by the Free Software Foundation *
14  * *
15  ***************************************************************************/
16 #ifndef _RL_SOCKET_H_
17 #define _RL_SOCKET_H_
18 
19 #include "rldefine.h"
20 #ifdef RLWIN32
21 #include <windows.h>
22 #ifdef IS_OLD_MSVCPP
23 #include <winsock.h>
24 #else
25 #include <winsock2.h>
26 #endif
27 #include <io.h>
28 #include <direct.h>
29 #else
30 #include <sys/time.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
34 #include <netdb.h>
35 #include "unistd.h"
36 #endif
37 
42 #define wsa rlwsa
43 int rlwsa();
44 
48 class rlSocket
49 {
50 public:
51 
53  {
54  SOCKET_ERR = -1,
56  LISTEN_ERR = -3,
57  ACCEPT_ERR = -4,
60  PORT_ERR = -7
61  };
62 
71  rlSocket(const char *adr, int port, int active);
72 
77  rlSocket(int socket);
78 
79 
84  virtual ~rlSocket();
85 
89  void setAdr(const char *adr);
90 
94  void setPort(int port);
95 
99  int getPort();
100 
104  void setActive(int active);
105 
115  int read(void *buf, int len, int timeout=0);
116 
126  int readStr(char *buf, int len, int timeout=0);
127 
133  int write(const void *buf, int len);
134 
140  int printf(const char *format, ...);
141 
147  int connect();
148 
153  int disconnect();
154 
162  int select(int timeout=0);
163 
168  int isConnected();
169 
175  int setIPVersion(int version);
176 
181  int getIPVersion();
182 
187 
193  int s;
194 
198  static int rlGetsockopt(int sockfd, int level, int optname, void *optval, int *optlen);
199 
203  static int rlSetsockopt(int sockfd, int level, int optname, const void *optval, int optlen);
204 
208  int rlGetsockopt(int level, int optname);
209 
213  int rlSetsockopt(int level, int optname);
214 
248  unsigned char sockaddr[16+48];
249 
250 private:
251  char adr[132];
252  int port;
253  int active;
254  int os;
255  int first;
258 };
259 
260 #endif