00001 #ifndef CLASSLIB_INET_SOCKET_H
00002 # define CLASSLIB_INET_SOCKET_H
00003
00004
00005
00006 # include "classlib/iobase/Socket.h"
00007 # include <string>
00008
00009
00010
00011
00012
00013 struct sockaddr_in;
00014
00015 namespace lat {
00016
00017
00018
00019
00020
00021 class InetAddress : public SocketAddress
00022 {
00023 public:
00024 InetAddress (unsigned short port = 0);
00025 InetAddress (unsigned long address, unsigned short port);
00026 InetAddress (unsigned long address, const char *service,
00027 const char *proto = "tcp");
00028 InetAddress (const char *host, unsigned short port);
00029 InetAddress (const char *host, const char *service,
00030 const char *proto = "tcp");
00031 InetAddress (const InetAddress &a);
00032 ~InetAddress (void);
00033 InetAddress &operator= (const InetAddress &x);
00034
00035 virtual size_t size (void) const;
00036 virtual int family (void) const;
00037 virtual sockaddr * address (void) const;
00038
00039 int port (void) const;
00040 std::string hostname (void) const;
00041
00042 protected:
00043 void port (const char *service, const char *proto = "tcp");
00044 void address (const char *host);
00045
00046 private:
00047 sockaddr_in *m_address;
00048 };
00049
00051
00052 class InetSocket : public Socket
00053 {
00054 public:
00055 InetSocket (void);
00056 InetSocket (int type, int protocol = 0);
00057 InetSocket (const InetAddress &to,
00058 int type = SocketConst::TypeStream,
00059 int protocol = 0);
00060 ~InetSocket (void);
00061
00062 virtual void create (int type = SocketConst::TypeStream,
00063 int protocol = 0);
00064
00065 virtual void bind (const InetAddress &a);
00066 virtual void connect (const InetAddress &a);
00067
00068 virtual InetAddress sockname (void);
00069 virtual InetAddress peername (void);
00070
00071
00072 using Socket::read;
00073 using Socket::peek;
00074 using Socket::write;
00075
00076 virtual IOSize read (void *into, IOSize n, InetAddress &source);
00077 IOSize read (IOBuffer into, InetAddress &source);
00078 virtual IOSize peek (void *into, IOSize n, InetAddress &source);
00079 IOSize peek (IOBuffer into, InetAddress &source);
00080 virtual IOSize write (const void *from, IOSize n, const InetAddress &dest);
00081 IOSize write (IOBuffer from, const InetAddress &dest);
00082
00083 protected:
00084 virtual Socket * copy (void);
00085 };
00086
00087
00088
00089
00090 }
00091 #endif // CLASSLIB_INET_SOCKET_H