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 int fd_) 00041 : m_path (0), m_rdbuf (new Socketbuf (this)) { 00042 trace_with_mask("IPv4Socket::IPv4Socket(fd_)",SOCKTRACE); 00043 00044 m_fd = fd_; 00045 } 00046 00048 ~IPv4Socket() { 00049 trace_with_mask("IPv4Socket::~IPv4Socket",SOCKTRACE); 00050 this->close (); 00051 00052 if (m_rdbuf != 0) { 00053 delete m_rdbuf; 00054 } 00055 } 00056 00062 IPv4Socket* clone () const; 00063 00064 00072 bool open(const int domain_); 00073 00077 bool close(); 00078 00088 bool connect(const Address& address_); 00089 00097 virtual bool bind (const Address& my_address_); 00098 00109 IPv4Socket* accept (); 00110 00121 int read (char* buf_, const unsigned int size_); 00122 00129 int write (const char* buf_, const unsigned int size_); 00130 00131 00133 const int getHandler () const { return m_fd; } 00134 00136 const int getDomain () const { return m_type; } 00137 00144 virtual Streambuf* rdbuf () { return m_rdbuf; } 00145 00153 virtual Streambuf* rdbuf (Streambuf* sb_); 00154 00160 virtual int in_avail () const { return m_rdbuf->in_avail (); } 00161 00162 private: 00163 // No copying 00164 IPv4Socket (const IPv4Socket&); 00165 IPv4Socket& operator= (const IPv4Socket&); 00166 00167 private: 00169 00171 char* m_path; 00172 00174 Streambuf* m_rdbuf; 00175 }; 00176 00177 } // end namespace ASSA 00178 00179 #endif // IPV4_SOCKET_Hh 00180 00181 00182