00001 #ifndef CLASSLIB_SOCKET_H
00002 # define CLASSLIB_SOCKET_H
00003
00004
00005
00006 # include "classlib/iobase/IOChannel.h"
00007 # include "classlib/iobase/SocketConst.h"
00008 # include <string>
00009
00010
00011
00012
00013
00014 struct sockaddr;
00015
00016 namespace lat {
00017
00018
00019
00020
00021
00024 class SocketAddress
00025 {
00026 public:
00027 virtual ~SocketAddress (void);
00028
00029 virtual size_t size (void) const = 0;
00030 virtual int family (void) const = 0;
00031 virtual sockaddr * address (void) const = 0;
00032 };
00033
00037
00046 class Socket : public IOChannel
00047 {
00048 public:
00049 ~Socket (void);
00050
00051
00052 virtual void oob (bool process = true);
00053 virtual void shutdown (int mode);
00054 virtual void close (void);
00055 virtual void abort (void);
00056
00057 virtual void listen (int queuelen = 1);
00058
00059 static bool hasopt (int option);
00060 virtual int getopt (int option,
00061 int level = SocketConst::OptLevelSocket) const;
00062 virtual int getopt (int option, void *p, size_t n,
00063 int level = SocketConst::OptLevelSocket) const;
00064 virtual void setopt (int option, int n,
00065 int level = SocketConst::OptLevelSocket) const;
00066 virtual void setopt (int option, const void *p, size_t n,
00067 int level = SocketConst::OptLevelSocket) const;
00068
00069 virtual int type (void) const;
00070 virtual int linger (int time = -1) const;
00071
00072
00073
00074 using IOChannel::read;
00075 using IOChannel::write;
00076
00077 virtual IOSize read (void *into, IOSize n);
00078 virtual IOSize peek (void *into, IOSize n);
00079 IOSize peek (IOBuffer into);
00080 virtual IOSize write (const void *from, IOSize n);
00081
00082 virtual Socket * accept (void);
00083
00084 protected:
00085 Socket (void);
00086
00087 void create (int af, int type, int protocol);
00088
00089 size_t sockname (SocketAddress &addr);
00090 size_t peername (SocketAddress &addr);
00091
00092 void bind (const SocketAddress &addr);
00093 void connect (const SocketAddress &addr);
00094 virtual Socket * copy (void) = 0;
00095
00096 IOSize read (void *into, IOSize n, SocketAddress &source);
00097 IOSize peek (void *into, IOSize n, SocketAddress &source);
00098 IOSize write (const void *from, IOSize n, const SocketAddress &dest);
00099
00100 virtual void select (IOSelectMethod *to, const IOSelectRequest &req);
00101
00102 private:
00103 static void sysinit (void);
00104
00105 void *m_extra;
00106 bool m_oob;
00107 };
00108
00109
00110
00111
00112 }
00113 #endif // CLASSLIB_SOCKET_H