version 3.0
This commit is contained in:
commit
d837490606
209 changed files with 19662 additions and 0 deletions
0
io/net/Makefile
Normal file
0
io/net/Makefile
Normal file
4
io/net/lib.mk
Normal file
4
io/net/lib.mk
Normal file
|
@ -0,0 +1,4 @@
|
|||
VPATH+= ${TOPDIR}/io/net
|
||||
|
||||
SRCS+= tcp_server.cc
|
||||
SRCS+= udp_server.cc
|
64
io/net/tcp_server.cc
Normal file
64
io/net/tcp_server.cc
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2008-2012 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <io/net/tcp_server.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: tcp_server.cc //
|
||||
// Description: base class for a connection oriented network server //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TCPServer::listen (SocketAddressFamily family, const std::string& name)
|
||||
{
|
||||
if (socket_)
|
||||
{
|
||||
socket_->close (0);
|
||||
delete socket_;
|
||||
}
|
||||
|
||||
socket_ = Socket::create (family, SocketTypeStream, "tcp", name);
|
||||
if (! socket_)
|
||||
{
|
||||
ERROR("/tcp/server") << "Unable to create socket.";
|
||||
return false;
|
||||
}
|
||||
if (! socket_->bind (name))
|
||||
{
|
||||
ERROR("/tcp/server") << "Socket bind failed";
|
||||
return false;
|
||||
}
|
||||
if (! socket_->listen ())
|
||||
{
|
||||
ERROR("/tcp/server") << "Socket listen failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
73
io/net/tcp_server.h
Normal file
73
io/net/tcp_server.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2008-2011 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef IO_NET_TCP_SERVER_H
|
||||
#define IO_NET_TCP_SERVER_H
|
||||
|
||||
#include <io/socket/socket.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: tcp_server.h //
|
||||
// Description: base class for a connection oriented network server //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TCPServer
|
||||
{
|
||||
LogHandle log_;
|
||||
Socket* socket_;
|
||||
|
||||
public:
|
||||
TCPServer () : log_("/tcp/server"), socket_(0)
|
||||
{ }
|
||||
|
||||
~TCPServer ()
|
||||
{
|
||||
delete socket_;
|
||||
}
|
||||
|
||||
bool listen (SocketAddressFamily family, const std::string& name);
|
||||
|
||||
Action* accept (SocketEventCallback* cb)
|
||||
{
|
||||
return (socket_ ? socket_->accept (cb) : 0);
|
||||
}
|
||||
|
||||
Action* close (EventCallback* cb = 0)
|
||||
{
|
||||
return (socket_ ? socket_->close (cb) : 0);
|
||||
}
|
||||
|
||||
std::string getsockname () const
|
||||
{
|
||||
return (socket_ ? socket_->getsockname () : std::string ());
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* !IO_NET_TCP_SERVER_H */
|
59
io/net/udp_server.cc
Normal file
59
io/net/udp_server.cc
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2010 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <io/net/udp_server.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: udp_server.cc //
|
||||
// Description: base class for a datagram network server //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool UDPServer::listen (SocketAddressFamily family, const std::string& name)
|
||||
{
|
||||
if (socket_)
|
||||
{
|
||||
socket_->close (0);
|
||||
delete socket_;
|
||||
}
|
||||
|
||||
socket_ = Socket::create (family, SocketTypeDatagram, "udp", name);
|
||||
if (! socket_)
|
||||
{
|
||||
ERROR("/udp/server") << "Unable to create socket.";
|
||||
return false;
|
||||
}
|
||||
if (! socket_->bind (name))
|
||||
{
|
||||
ERROR("/udp/server") << "Socket bind failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
73
io/net/udp_server.h
Normal file
73
io/net/udp_server.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2011 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef IO_NET_UDP_SERVER_H
|
||||
#define IO_NET_UDP_SERVER_H
|
||||
|
||||
#include <io/socket/socket.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: udp_server.h //
|
||||
// Description: base class for a datagram network server //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class UDPServer
|
||||
{
|
||||
LogHandle log_;
|
||||
Socket* socket_;
|
||||
|
||||
public:
|
||||
UDPServer () : log_("/udp/server"), socket_(0)
|
||||
{ }
|
||||
|
||||
~UDPServer ()
|
||||
{
|
||||
delete socket_;
|
||||
}
|
||||
|
||||
bool listen (SocketAddressFamily family, const std::string& name);
|
||||
|
||||
Action* read (EventCallback* cb)
|
||||
{
|
||||
return (socket_ ? socket_->read (cb) : 0);
|
||||
}
|
||||
|
||||
Action* close (EventCallback* cb)
|
||||
{
|
||||
return (socket_ ? socket_->close (cb) : 0);
|
||||
}
|
||||
|
||||
std::string getsockname (void) const
|
||||
{
|
||||
return (socket_ ? socket_->getsockname () : std::string ());
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* !IO_NET_UDP_SERVER_H */
|
Loading…
Add table
Add a link
Reference in a new issue