3 #include "stg/sgcp_utils.h"
9 #include <sys/socket.h>
10 #include <netinet/in.h>
11 #include <netinet/tcp.h>
13 using STG::SGCP::TCPProto;
15 TCPProto::TCPProto(ba::io_service& ios)
26 ConnectionPtr TCPProto::connect(const std::string& address, uint16_t port)
29 ConnectionPtr conn = boost::make_shared(m_ios);
30 conn.socket().connect(ba::local::stream_protocol::enpoint(address, port), ec);
32 throw Error(ec.message());
37 void TCPProto::bind(const std::string& address, uint16_t port, Proto::AcceptHandler handler)
40 m_acceptor.bind(address, ec);
42 throw Error(ec.message());
44 TCPConn* conn = new TCPConn(m_ios);
45 m_acceptor.async_accept(conn->socket(), conn->endpoint(), boost::bind(&TCPProto::m_handleAccept, this, conn, handler, boost::_1);
48 void TCPProto::m_handleAccept(TCPConn* conn, Proto::AcceptHandler handler, const boost::system::error_code& ec)
52 handler(NULL, "", ec.message());
55 handler(conn, conn->enpoint().address(), "");