00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __SOCKETACCESSOR_H
00025 #define __SOCKETACCESSOR_H
00026
00027 #include <stlib/IOAccessor.h>
00028 #include <stlib/ByteArray.h>
00029 #include <stlib/String.h>
00030 #include <stlib/GenericException.h>
00031
00037 namespace Net {
00038
00039 class IPSocketAddress;
00040
00041 class SocketAccessor : public Core::IOAccessor
00042 {
00043 protected:
00045 int descriptor;
00046 int sckFamily;
00047
00048 protected:
00050 SocketAccessor(int descr);
00051
00052 public:
00053 SocketAccessor(int family, int type, int protocol = 0);
00054
00055
00056 static SocketAccessor *newTCP(void);
00057 static SocketAccessor *newTCPclientToHost(ByteArray *hostAddr, int port);
00058 static SocketAccessor *newTCPclientToHost(String *hostName, int port);
00059 static SocketAccessor *newTCPserverAtPort(int port);
00060 static SocketAccessor *newTCPserverAt(ByteArray *hostAddr, int port);
00061 static SocketAccessor *newUDP(void);
00062 static SocketAccessor *newUDPclientToHost(ByteArray *hostAddr, int port);
00063 static SocketAccessor *newUDPclientToHost(String *hostName, int port);
00064 static SocketAccessor *newUDPserverAtPort(int port);
00065 static SocketAccessor *newUDPserverAt(ByteArray *hostAddr, int port);
00066
00067
00068 virtual String *className(void) const;
00069 static String *getHostname(void);
00070
00071
00072 virtual void close(void);
00073
00074
00075 virtual long bufferSize(void);
00076 virtual IPSocketAddress *myAddress(void);
00077 virtual IPSocketAddress *peerAddress(void);
00078
00079
00080 virtual int readInto(ByteArray *buffer)
00081 { return IOAccessor::readInto(buffer); }
00082 virtual int readInto(ByteArray *buffer, long startIndex, long count);
00083
00084 virtual int writeFrom(ByteArray *buffer)
00085 { return IOAccessor::writeFrom(buffer); }
00086 virtual int writeFrom(ByteArray *buffer, long startIndex, long count);
00087
00088
00089 virtual void seekTo(long position);
00090
00091
00092 virtual void readWait(void);
00093 virtual bool readWaitWithTimeout(int milliseconds);
00094 virtual void writeWait(void);
00095 virtual bool writeWaitWithTimeout(int milliseconds);
00096
00097
00098 virtual void bindTo(IPSocketAddress *address);
00099 virtual void connectTo(IPSocketAddress *address);
00100 virtual void listenFor(int queueLength);
00101
00102
00103 virtual SocketAccessor *accept(void);
00104 };
00105
00106 };
00107
00108 #endif