|
rllib
1
|
#include <rlsocket.h>

Public Types | |
| enum | SocketEnum { SOCKET_ERR = -1, SETSOCKOPT_ERR = -2, LISTEN_ERR = -3, ACCEPT_ERR = -4, INET_ADDR_ERR = -5, CONNECT_ERR = -6, PORT_ERR = -7 } |
Public Member Functions | |
| rlSocket (const char *adr, int port, int active) | |
| rlSocket (int socket) | |
| virtual | ~rlSocket () |
| void | setAdr (const char *adr) |
| void | setPort (int port) |
| int | getPort () |
| void | setActive (int active) |
| int | read (void *buf, int len, int timeout=0) |
| int | readStr (char *buf, int len, int timeout=0) |
| int | readHttpHeader (rlString *header, int timeout=0) |
| int | write (const void *buf, int len) |
| int | printf (const char *format,...) |
| int | connect () |
| int | disconnect () |
| int | select (int timeout=0) |
| int | isConnected () |
| int | setIPVersion (int version) |
| int | getIPVersion () |
| int | sendProcessViewBrowserButtonEvent (int id) |
| int | rlGetsockopt (int level, int optname) |
| int | rlSetsockopt (int level, int optname) |
| int | readHttpContentLength (int timeout) |
Static Public Member Functions | |
| static int | rlGetsockopt (int sockfd, int level, int optname, void *optval, int *optlen) |
| static int | rlSetsockopt (int sockfd, int level, int optname, const void *optval, int optlen) |
Public Attributes | |
| int | s |
| unsigned char | sockaddr [16+48] |
Private Attributes | |
| char | adr [132] |
| int | port |
| int | active |
| int | os |
| int | first |
| int | prefer_ipv6 |
| int | rl_ipversion |
class for encapsulating TCP/IP socket calls
Definition at line 46 of file rlsocket.h.
| enum rlSocket::SocketEnum |
| Enumerator | |
|---|---|
| SOCKET_ERR | |
| SETSOCKOPT_ERR | |
| LISTEN_ERR | |
| ACCEPT_ERR | |
| INET_ADDR_ERR | |
| CONNECT_ERR | |
| PORT_ERR | |
Definition at line 50 of file rlsocket.h.
| rlSocket::rlSocket | ( | const char * | adr, |
| int | port, | ||
| int | active | ||
| ) |
construct a new rlSocket but do not connect
adr = hostname | dotted address
port = port number of socket
active = 0 wait for connections with accept()
active = 1 open the connection with connect()
active = 2 neither accept() nor connect()
Definition at line 130 of file rlsocket.cpp.
| rlSocket::rlSocket | ( | int | socket | ) |
|
virtual |
destruct the socket
attention if active = 0 the socket will still be bound to port
Definition at line 155 of file rlsocket.cpp.
| int rlSocket::connect | ( | ) |
connect
return >= 0 socket used
return < 0 error (see: enum SocketEnum)
Definition at line 307 of file rlsocket.cpp.
| int rlSocket::disconnect | ( | ) |
| int rlSocket::getIPVersion | ( | ) |
| int rlSocket::getPort | ( | ) |
get port
Definition at line 181 of file rlsocket.cpp.
| int rlSocket::isConnected | ( | ) |
return == 1 socket is connected
return == 0 socket is not connected
Definition at line 543 of file rlsocket.cpp.
| int rlSocket::printf | ( | const char * | format, |
| ... | |||
| ) |
similar to printf
return > 0 length of data written
return < 0 error
Definition at line 570 of file rlsocket.cpp.
| int rlSocket::read | ( | void * | buf, |
| int | len, | ||
| int | timeout = 0 |
||
| ) |
read a block of data
len = length of data to be read
timeout = 0 wait indefinite
timeout > 0 wait at maximum for timeout milliseconds
return > 0 length of message read
return == 0 timeout
return < 0 error
Definition at line 191 of file rlsocket.cpp.
| int rlSocket::readHttpContentLength | ( | int | timeout | ) |
read the response to a http get request until Content-Length is received
Tip: char line[256];
Definition at line 639 of file rlsocket.cpp.
| int rlSocket::readHttpHeader | ( | rlString * | header, |
| int | timeout = 0 |
||
| ) |
read a http header and return Content-Length
return < 0 error
Definition at line 256 of file rlsocket.cpp.
| int rlSocket::readStr | ( | char * | buf, |
| int | len, | ||
| int | timeout = 0 |
||
| ) |
read a '
' terminated string
len = max length of data to be read
timeout = 0 wait indefinite
timeout > 0 wait at maximum for timeout milliseconds
return > 0 length of message read
return == 0 timeout
return < 0 error
Definition at line 219 of file rlsocket.cpp.
|
static |
| int rlSocket::rlGetsockopt | ( | int | level, |
| int | optname | ||
| ) |
get an option from this->s
Definition at line 626 of file rlsocket.cpp.
|
static |
portable version of setsockopt
Definition at line 617 of file rlsocket.cpp.
| int rlSocket::rlSetsockopt | ( | int | level, |
| int | optname | ||
| ) |
set an option on this->s
Definition at line 633 of file rlsocket.cpp.
| int rlSocket::select | ( | int | timeout = 0 | ) |
wait for data arriving on socket
timeout > 0 timeout in milliseconds
timeout == 0 indefinite timeout
return = 1 DATA_AVAILABLE
return = 0 TIMEOUT
Definition at line 549 of file rlsocket.cpp.
| int rlSocket::sendProcessViewBrowserButtonEvent | ( | int | id | ) |
This method is intendet for data providers implemented as ProcessViewServer
Definition at line 583 of file rlsocket.cpp.
| void rlSocket::setActive | ( | int | active | ) |
set port active = 0|1
Definition at line 186 of file rlsocket.cpp.
| void rlSocket::setAdr | ( | const char * | adr | ) |
| int rlSocket::setIPVersion | ( | int | version | ) |
default: prefer IPV4
if(ip==6) prefer IPV6
else prefer IPV4
Definition at line 588 of file rlsocket.cpp.
| void rlSocket::setPort | ( | int | port | ) |
set port to a different port than in the constructor
Definition at line 176 of file rlsocket.cpp.
| int rlSocket::write | ( | const void * | buf, |
| int | len | ||
| ) |
write a block of data
return > 0 length of data written
return < 0 error
Definition at line 282 of file rlsocket.cpp.
|
private |
Definition at line 263 of file rlsocket.h.
|
private |
Definition at line 261 of file rlsocket.h.
|
private |
Definition at line 265 of file rlsocket.h.
|
private |
Definition at line 264 of file rlsocket.h.
|
private |
Definition at line 262 of file rlsocket.h.
|
private |
Definition at line 266 of file rlsocket.h.
|
private |
Definition at line 267 of file rlsocket.h.
| int rlSocket::s |
this is the real socket used for communication
s >= 0 connected
s == -1 disconnected
Definition at line 197 of file rlsocket.h.
| unsigned char rlSocket::sockaddr[16+48] |
this array can be casted to (struct sockaddr *) &sockaddr[0];
in case of active==0 it will store sockaddr of the last client
(48 bytes spare) struct sockaddr {
unsigned short sa_family; // address family, AF_xxx
char sa_data[14]; // 14 bytes of protocol address
}; // IPv4 AF_INET sockets:
struct sockaddr_in {
short sin_family; // e.g. AF_INET, AF_INET6
unsigned short sin_port; // e.g. htons(3490)
struct in_addr sin_addr; // see struct in_addr, below
char sin_zero[8]; // zero this if you want to
};
struct in_addr {
unsigned long s_addr; // load with inet_pton()
}; // IPv6 AF_INET6 sockets:
struct sockaddr_in6 {
u_int16_t sin6_family; // address family, AF_INET6
u_int16_t sin6_port; // port number, Network Byte Order
u_int32_t sin6_flowinfo; // IPv6 flow information
struct in6_addr sin6_addr; // IPv6 address
u_int32_t sin6_scope_id; // Scope ID
};
struct in6_addr {
unsigned char s6_addr[16]; // load with inet_pton()
};
Definition at line 258 of file rlsocket.h.
1.8.14