basic_socket.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa AKIYAMA, Hiroki SHIMORA
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_NET_BASIC_SOCKET_H
00033 #define RCSC_NET_BASIC_SOCKET_H
00034 
00035 #include <boost/scoped_ptr.hpp>
00036 #include <cstddef>
00037 
00038 namespace rcsc {
00039 
00040 struct AddrImpl;
00041 
00046 class BasicSocket {
00047 private:
00049     int M_fd;
00050 
00051 protected:
00053     boost::scoped_ptr< AddrImpl > M_dest;
00054 
00055 public:
00060     enum SocketType {
00061         DATAGRAM_TYPE,
00062         STREAM_TYPE,
00063     };
00064 
00065 public:
00069     virtual ~BasicSocket();
00070 
00074     int fd() const
00075       {
00076           return M_fd;
00077       }
00078 
00079 protected:
00084     BasicSocket();
00085 
00090     void setDestPort( const void * addr );
00091 
00092 
00097     bool open( const SocketType type );
00098 
00104     bool bind( const int port = 0 );
00105 
00112     bool setAddr( const char * hostname,
00113                   const int port );
00114 
00119     int setNonBlocking();
00120 
00125     int connectToPresetAddr();
00126 
00133     int writeToStream( const char * data,
00134                        const std::size_t len );
00135 
00144     int readFromStream( char * buf,
00145                         const std::size_t len );
00146 
00153     int sendDatagramPacket( const char * data,
00154                             const std::size_t len );
00155 
00166     int receiveDatagramPacket( char * buf,
00167                                const std::size_t len,
00168                                const bool overwrite_dist_addr = false );
00169 
00170 public:
00171 
00176     bool isOpen() const
00177       {
00178           return fd() != -1;
00179       }
00180 
00185     int close();
00186 
00187 
00194     virtual
00195     int send( const char * data,
00196               const std::size_t len ) = 0;
00197 
00206     virtual
00207     int receive( char * buf,
00208                  const std::size_t len ) = 0;
00209 };
00210 
00211 } // end namespace
00212 
00213 #endif

librcscに対してThu May 1 15:41:20 2008に生成されました。  doxygen 1.5.0