NetLink Sockets C++ 1.0.0
Networking C++ Library @ Get NetLink Sockets C++ Library at SourceForge.net. Fast, secure and Free Open Source software downloads

include/netlink/socket.h

00001 /*
00002     NetLink Sockets: Networking C++ library
00003     Copyright 2012 Pedro Francisco Pareja Ruiz (PedroPareja@Gmail.com)
00004 
00005     This file is part of NetLink Sockets.
00006 
00007     NetLink Sockets is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     NetLink Sockets is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with NetLink Sockets. If not, see <http://www.gnu.org/licenses/>.
00019 
00020 */
00021 
00022 #ifndef __NL_SOCKET
00023 #define __NL_SOCKET
00024 
00025 #include "netlink/core.h"
00026 
00027 
00028 NL_NAMESPACE
00029 
00039 class Socket {
00040 
00041     private:
00042 
00043         string      _hostTo;
00044         string      _hostFrom;
00045         unsigned    _portTo;
00046         unsigned    _portFrom;
00047         Protocol    _protocol;
00048         IPVer       _ipVer;
00049         SocketType  _type;
00050         bool        _blocking;
00051         unsigned    _listenQueue;
00052 
00053         int         _socketHandler;
00054 
00055 
00056     public:
00057 
00058         Socket(const string& hostTo, unsigned portTo, Protocol protocol = TCP, IPVer ipVer = ANY);
00059 
00060         Socket(unsigned portFrom, Protocol protocol = TCP, IPVer ipVer = IP4, const string& hostFrom = "", unsigned listenQueue = DEFAULT_LISTEN_QUEUE);
00061 
00062         Socket(const string& hostTo, unsigned portTo, unsigned portFrom, IPVer ipVer = ANY);
00063 
00064         ~Socket();
00065 
00066 
00067         Socket* accept();
00068 
00069         int read(void* buffer, size_t bufferSize);
00070         void send(const void* buffer, size_t size);
00071 
00072         int readFrom(void* buffer, size_t bufferSize, string* HostFrom, unsigned* portFrom = NULL);
00073         void sendTo(const void* buffer, size_t size, const string& hostTo, unsigned portTo);
00074 
00075         int nextReadSize() const;
00076 
00077         void disconnect();
00078 
00079         const string&   hostTo() const;
00080         const string&   hostFrom() const;
00081         unsigned        portTo() const;
00082         unsigned        portFrom() const;
00083         Protocol        protocol() const;
00084         IPVer           ipVer() const;
00085         SocketType      type() const;
00086         bool            blocking() const;
00087         unsigned        listenQueue() const;
00088         int             socketHandler() const;
00089 
00090 
00091         void blocking(bool blocking);
00092 
00093 
00094     private:
00095 
00096         void initSocket();
00097         Socket();
00098 
00099 };
00100 
00101 #include <netlink/socket.inline.h>
00102 
00103 NL_NAMESPACE_END
00104 
00105 #endif
 All Classes Namespaces Files Functions Enumerations Enumerator