rllib  1
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 #include "rlstring.h"
21 #ifdef RLWIN32
22 #include <winsock2.h>
23 #include <windows.h>
24 #include <io.h>
25 #include <direct.h>
26 #else
27 #include <sys/time.h>
28 #include <sys/socket.h>
29 #include <netinet/in.h>
30 #include <arpa/inet.h>
31 #include <netdb.h>
32 #include "unistd.h"
33 #endif
34 
39 #define wsa rlwsa
40 int rlwsa();
41 int rlScoketWrite(int *socket, const void *buf, int len);
42 
46 class rlSocket
47 {
48 public:
49 
51  {
52  SOCKET_ERR = -1,
54  LISTEN_ERR = -3,
55  ACCEPT_ERR = -4,
58  PORT_ERR = -7
59  };
60 
69  rlSocket(const char *adr, int port, int active);
70 
75  rlSocket(int socket);
76 
77 
82  virtual ~rlSocket();
83 
87  void setAdr(const char *adr);
88 
92  void setPort(int port);
93 
97  int getPort();
98 
102  void setActive(int active);
103 
113  int read(void *buf, int len, int timeout=0);
114 
124  int readStr(char *buf, int len, int timeout=0);
125 
130  int readHttpHeader(rlString *header, int timeout=0);
131 
137  int write(const void *buf, int len);
138 
144  int printf(const char *format, ...);
145 
151  int connect();
152 
157  int disconnect();
158 
166  int select(int timeout=0);
167 
172  int isConnected();
173 
179  int setIPVersion(int version);
180 
185  int getIPVersion();
186 
191 
197  int s;
198 
202  static int rlGetsockopt(int sockfd, int level, int optname, void *optval, int *optlen);
203 
207  static int rlSetsockopt(int sockfd, int level, int optname, const void *optval, int optlen);
208 
212  int rlGetsockopt(int level, int optname);
213 
217  int rlSetsockopt(int level, int optname);
218 
223  int readHttpContentLength(int timeout);
224 
258  unsigned char sockaddr[16+48];
259 
260 private:
261  char adr[132];
262  int port;
263  int active;
264  int os;
265  int first;
268 };
269 
270 #endif
int setIPVersion(int version)
Definition: rlsocket.cpp:604
int write(const void *buf, int len)
Definition: rlsocket.cpp:292
void setActive(int active)
Definition: rlsocket.cpp:186
int rlScoketWrite(int *socket, const void *buf, int len)
Definition: rlsocket.cpp:95
int rlwsa()
Definition: rlsocket.cpp:68
int readHttpHeader(rlString *header, int timeout=0)
Definition: rlsocket.cpp:266
virtual ~rlSocket()
Definition: rlsocket.cpp:155
int port
Definition: rlsocket.h:262
int first
Definition: rlsocket.h:265
void setPort(int port)
Definition: rlsocket.cpp:176
int readStr(char *buf, int len, int timeout=0)
Definition: rlsocket.cpp:224
unsigned char sockaddr[16+48]
Definition: rlsocket.h:258
rlSocket(const char *adr, int port, int active)
Definition: rlsocket.cpp:130
int sendProcessViewBrowserButtonEvent(int id)
Definition: rlsocket.cpp:599
char adr[132]
Definition: rlsocket.h:261
int read(void *buf, int len, int timeout=0)
Definition: rlsocket.cpp:191
static int rlSetsockopt(int sockfd, int level, int optname, const void *optval, int optlen)
Definition: rlsocket.cpp:633
int prefer_ipv6
Definition: rlsocket.h:266
SocketEnum
Definition: rlsocket.h:50
int select(int timeout=0)
Definition: rlsocket.cpp:565
int os
Definition: rlsocket.h:264
int getPort()
Definition: rlsocket.cpp:181
int connect()
Definition: rlsocket.cpp:321
int s
Definition: rlsocket.h:197
int disconnect()
Definition: rlsocket.cpp:545
int isConnected()
Definition: rlsocket.cpp:559
static int rlGetsockopt(int sockfd, int level, int optname, void *optval, int *optlen)
Definition: rlsocket.cpp:616
int active
Definition: rlsocket.h:263
int readHttpContentLength(int timeout)
Definition: rlsocket.cpp:655
void setAdr(const char *adr)
Definition: rlsocket.cpp:168
int getIPVersion()
Definition: rlsocket.cpp:611
int printf(const char *format,...)
Definition: rlsocket.cpp:586
int rl_ipversion
Definition: rlsocket.h:267