00001 // -*- c++ -*- 00002 //------------------------------------------------------------------------------ 00003 // IPv4Socket.h 00004 //------------------------------------------------------------------------------ 00005 // Copyright (c) 1998 by Vladislav Grinchenko 00006 // 00007 // This library is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU Library General Public 00009 // License as published by the Free Software Foundation; either 00010 // version 2 of the License, or (at your option) any later version. 00011 //------------------------------------------------------------------------------ 00012 #ifndef IPV4_SOCKET_Hh 00013 #define IPV4_SOCKET_Hh 00014 00015 #include "assa/Socket.h" 00016 #include "assa/Socketbuf.h" 00017 00024 namespace ASSA { 00025 class IPv4Socket : public Socket 00026 { 00027 public: 00029 static const int MAXTCPBUFSZ; 00030 00032 IPv4Socket() 00033 : m_path (0), m_rdbuf (new Socketbuf (this)) { 00034 trace_with_mask("IPv4Socket::IPv4Socket()",SOCKTRACE); 00035 } 00036 00040 IPv4Socket(const handler_t fd_) 00041 : m_path (0), m_rdbuf (new Socketbuf (this)) 00042 { 00043 trace_with_mask("IPv4Socket::IPv4Socket(fd_)",SOCKTRACE); 00044 00045 m_fd = fd_; // inherited from the parent class 00046 } 00047 00049 ~IPv4Socket() 00050 { 00051 trace_with_mask("IPv4Socket::~IPv4Socket",SOCKTRACE); 00052 this->close (); 00053 00054 if (m_rdbuf != 0) { 00055 delete m_rdbuf; 00056 } 00057 } 00058 00064 IPv4Socket* clone () const; 00065 00066 00074 bool open(const int domain_); 00075 00079 bool close(); 00080 00090 bool connect(const Address& address_); 00091 00099 virtual bool bind (const Address& my_address_); 00100 00111 IPv4Socket* accept (); 00112 00123 int read (char* buf_, const unsigned int size_); 00124 00131 int write (const char* buf_, const unsigned int size_); 00132 00133 00135 handler_t getHandler () const { return m_fd; } 00136 00138 const int getDomain () const { return m_type; } 00139 00146 virtual Streambuf* rdbuf () { return m_rdbuf; } 00147 00155 virtual Streambuf* rdbuf (Streambuf* sb_); 00156 00162 virtual int in_avail () const { return m_rdbuf->in_avail (); } 00163 00164 private: 00165 // No copying 00166 IPv4Socket (const IPv4Socket&); 00167 IPv4Socket& operator= (const IPv4Socket&); 00168 00169 private: 00171 00173 char* m_path; 00174 00176 Streambuf* m_rdbuf; 00177 }; 00178 00179 } // end namespace ASSA 00180 00181 #endif // IPV4_SOCKET_Hh 00182 00183 00184