00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef ULXR_TCPIP_CONNECTION_H
00031 #define ULXR_TCPIP_CONNECTION_H
00032
00033 #ifndef ULXR_OMIT_TCP_STUFF
00034
00035 #include <ulxmlrpcpp/ulxmlrpcpp.h>
00036
00037 #if defined(__WIN32__) || defined(_MSC_VER)
00038 #include <winsock2.h>
00039
00040 typedef int socklen_t;
00041 #endif
00042
00043 #ifdef __unix__
00044 #include <netdb.h>
00045 #include <arpa/inet.h>
00046 #include <netinet/in.h>
00047 #include <sys/socket.h>
00048 #endif
00049
00050 #include <ulxmlrpcpp/ulxr_connection.h>
00051
00052
00053 namespace ulxr {
00054
00055
00059 class ULXR_API_DECL0 TcpIpConnection : public Connection
00060 {
00061 public:
00062
00070 TcpIpConnection(bool server, const CppString &domain, unsigned port = 80);
00071
00077 void setProxy(long adr, unsigned port);
00078
00084 void setProxy(const CppString &domain, unsigned port);
00085
00092 TcpIpConnection(bool server, long adr = INADDR_ANY, unsigned port = 0);
00093
00096 virtual ~TcpIpConnection();
00097
00102 virtual Connection *detach();
00103
00106 virtual void open();
00107
00113 virtual bool accept(int timeout = 0);
00114
00117 virtual void close();
00118
00124 virtual void shutdown(int mode);
00125
00129 unsigned getPort();
00130
00134 CppString getHostName() const;
00135
00139 CppString getServerDomain() const;
00140
00146 CppString getPeerName() const;
00147
00152 void asciiToInAddr(const char *address,
00153 struct in_addr &saddr);
00154
00160 int abortOnClose(int bOn);
00161
00169 void setTcpNoDelay(bool bOn);
00170
00174 virtual CppString getInterfaceName();
00175
00179 virtual int getLastError();
00180
00184 bool isServerMode() const;
00185
00189 virtual int getServerHandle();
00190
00191 protected:
00192
00196 struct hostent *getHostAdress(const CppString &hostname);
00197
00201 virtual TcpIpConnection *makeClone();
00202
00207 virtual void decrementServerRef(bool shutdown = false);
00208
00209 class ServerSocketData;
00210
00215 void setServerData (ServerSocketData *serv_data);
00216
00220 ServerSocketData *getServerData () const;
00221
00222 private:
00223
00227 void init (unsigned port);
00228
00232 int doTcpNoDelay();
00233
00234 protected:
00235
00236 TcpIpConnection(const TcpIpConnection&);
00237
00238 private:
00239
00240
00241 TcpIpConnection& operator=(const TcpIpConnection&);
00242
00243 private:
00244
00245 struct PImpl;
00246 PImpl *pimpl;
00247 int noDelayOpt;
00248 };
00249
00250
00253 class ULXR_API_DECL0 TcpIpConnection::ServerSocketData
00254 {
00255 public:
00256
00260 ServerSocketData(int s_no);
00261
00264 virtual ~ServerSocketData();
00265
00269 int getSocket() const;
00270
00273 void close();
00274
00280 virtual void shutdown(int mode);
00281
00284 bool isOpen();
00285
00288 void incRef();
00289
00293 int decRef();
00294
00295 private:
00296
00297 int count;
00298 int socket_no;
00299 };
00300
00301
00302 }
00303
00304
00305 #endif // ULXR_OMIT_TCP_STUFF
00306
00307 #endif // ULXR_TCPIP_CONNECTION_H