/*************************************************************************** rlsocket.h - description ------------------- begin : Tue Jan 02 2001 copyright : (C) 2001 by Rainer Lehrig email : lehrig@t-online.de ***************************************************************************/ /*************************************************************************** * * * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as * * published by the Free Software Foundation * * * ***************************************************************************/ #ifndef _RL_SOCKET_H_ #define _RL_SOCKET_H_ #include "rldefine.h" /*!
you have to call this function before you use any sockets (at least under windows)*/ #define wsa rlwsa int rlwsa(); /*!
class for encapsulating TCP/IP socket calls*/ class rlSocket { public: enum SocketEnum { SOCKET_ERR = -1, SETSOCKOPT_ERR = -2, LISTEN_ERR = -3, ACCEPT_ERR = -4, INET_ADDR_ERR = -5, CONNECT_ERR = -6, PORT_ERR = -7 }; /*!
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()*/ rlSocket(const char *adr, int port, int active); /*!
construct a new rlSocket use connection on open socket*/ rlSocket(int socket); /*!
destruct the socket attention if active = 0 the socket will still be bound to port*/ virtual ~rlSocket(); /*!
set adr to a different adr than in the constructor*/ void setAdr(const char *adr); /*!
set port to a different port than in the constructor*/ void setPort(int port); /*!
get port*/ int getPort(); /*!
set port active = 0|1*/ void setActive(int active); /*!
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*/ int read(void *buf, int len, int timeout=0); /*!
read a '\n' 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*/ int readStr(char *buf, int len, int timeout=0); /*!
write a block of data return > 0 length of data written return < 0 error*/ int write(const void *buf, int len); /*!
similar to printf return > 0 length of data written return < 0 error*/ int printf(const char *format, ...); /*!
connect return >= 0 socket used return < 0 error (see: enum SocketEnum)*/ int connect(); /*!
disconnect return = 0*/ int disconnect(); /*!
wait for data arriving on socket timeout > 0 timeout in milliseconds timeout == 0 indefinite timeout return = 1 DATA_AVAILABLE return = 0 TIMEOUT*/ int select(int timeout=0); /*!
return == 1 socket is connected return == 0 socket is not connected*/ int isConnected(); /*!
This method is intendet for data providers implemented as ProcessViewServer*/ int sendProcessViewBrowserButtonEvent(int id); /*!
this is the real socket used for communication s >= 0 connected s == -1 disconnected*/ int s; private: char adr[132]; int port; int active; int os; int first; }; #endif