00001 /*************************************************************************** 00002 * Copyright (C) 2001 by Rick L. Vinyard, Jr. * 00003 * rvinyard@cs.nmsu.edu * 00004 * * 00005 * This file is part of the conexus library. * 00006 * * 00007 * The conexus library is free software; you can redistribute it and/or * 00008 * modify it under the terms of the GNU General Public License * 00009 * version 3 as published by the Free Software Foundation. * 00010 * * 00011 * The conexus library is distributed in the hope that it will be * 00012 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * 00013 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this software. If not see <http://www.gnu.org/licenses/>. * 00018 ***************************************************************************/ 00019 #ifndef CONEXUSNSPRSOCKET_H 00020 #define CONEXUSNSPRSOCKET_H 00021 00022 #include <sys/types.h> 00023 00024 #include <iostream> 00025 00026 #include <utility> 00027 00028 #include <conexus-nspr/filedescriptor.h> 00029 #include <conexus/ipv4_address.h> 00030 #include <conexus/except.h> 00031 00032 namespace Conexus 00033 { 00034 00035 namespace NSS 00036 { 00037 class SSLSocket; 00038 } 00039 00040 namespace NSPR 00041 { 00042 00056 class Socket: public FileDescriptor 00057 { 00058 protected: 00059 00060 Socket( ) throw (); 00061 00062 public: 00063 00064 typedef ConexusPointer<Socket> pointer; 00065 00066 virtual ~Socket() throw (); 00067 00072 virtual void close( bool force = false ) throw ( close_exception ); 00073 00079 virtual void bind() throw ( bind_exception ); 00080 00088 virtual void bind( const Conexus::Address& a ) throw ( bind_exception ); 00089 00095 virtual void connect() throw ( connect_exception ); 00096 00104 virtual void connect( const Address& a ) throw ( connect_exception ); 00105 00113 virtual void listen( int backlog = 0 ); 00114 00115 virtual ssize_t writeto(Address& a, const Data data) throw (write_exception); 00116 00117 virtual void set_option( PRSocketOptionData& option ); 00118 00119 virtual void change_state( long states ) throw ( state_exception ); 00120 00121 sigc::signal<void> signal_bound(); 00122 00123 sigc::signal<void> signal_connected(); 00124 00125 sigc::signal<void> signal_listening(); 00126 00127 bool is_bound(); 00128 00129 bool is_connected(); 00130 00131 bool is_listening(); 00132 00133 bool is_accepted(); 00134 00135 bool set_non_blocking(bool set=true); 00136 00137 bool is_non_blocking(); 00138 00139 virtual Conexus::IPv4::Address& local_address(); 00140 00141 virtual Conexus::IPv4::Address& remote_address(); 00142 00143 virtual void set_remote_address( Conexus::IPv4::Address addr ); 00144 00145 virtual void unset_remote_address(); 00146 00147 virtual void set_local_address( Conexus::IPv4::Address addr ); 00148 00149 protected: 00150 friend class Conexus::NSS::SSLSocket; 00151 00152 Conexus::IPv4::Address m_local_address; 00153 Conexus::IPv4::Address m_remote_address; 00154 bool m_remote_address_set; 00155 00156 bool m_non_blocking; 00157 00158 virtual size_t write_data( const Data data, Timeout timeout ) throw ( write_exception ); 00159 00167 virtual Data read_data( size_t s, Timeout timeout ) throw ( read_exception ); 00168 00169 virtual void set_state_closed(); 00170 virtual void set_state_bound(); 00171 virtual void set_state_connected(); 00172 virtual void set_state_listening(); 00173 00174 sigc::signal<void> m_signal_bound; 00175 sigc::signal<void> m_signal_connected; 00176 sigc::signal<void> m_signal_listening; 00177 00178 virtual void on_local_address_changed( ); 00179 virtual void on_remote_address_changed( ); 00180 00181 void on_local_address_changed_proxy( ); 00182 void on_remote_address_changed_proxy( ); 00183 00184 }; 00185 00186 } 00187 } 00188 00189 #endif