当前位置: 首页>>代码示例>>C++>>正文


C++ TCPSocket::getSocket方法代码示例

本文整理汇总了C++中TCPSocket::getSocket方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPSocket::getSocket方法的具体用法?C++ TCPSocket::getSocket怎么用?C++ TCPSocket::getSocket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TCPSocket的用法示例。


在下文中一共展示了TCPSocket::getSocket方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SocketConnectionRefused

TCPSocket *TCPSocket::connect(SockAddress dest, int port)
    throw(SocketConnectionRefused)
{
    TCPSocket *sock;

    if(dest.type() == SockAddress::V4)
    {
        sock = new TCPSocket(::socket(AF_INET, SOCK_STREAM, 0));

        struct sockaddr_in address;
        address.sin_family = AF_INET;
        address.sin_addr.s_addr = htonl(dest.v4toUint());
        address.sin_port = htons(port);

        memset(&(address.sin_zero), 0, 8);

        if(::connect(sock->getSocket(), (struct sockaddr*)&address,
                sizeof(address)) == -1)
            throw SocketConnectionRefused();
    }
    else
        throw SocketConnectionRefused();

    return sock;
}
开发者ID:remram44,项目名称:network,代码行数:25,代码来源:TCP.cpp

示例2: CreateEvent

SocketPort::SocketPort(SocketService *svc, TCPSocket &tcp) :
Socket(accept(tcp.getSocket(), NULL, NULL))
{
	detect_pending = true;
	detect_output = false;
	detect_disconnect = true;

#ifdef WIN32
	// FIXME: error handling
	event = CreateEvent(NULL,TRUE,FALSE,NULL);
#endif
	next = prev = NULL;
	service = NULL;

	// FIXME: use macro here and in other files...
#ifndef WIN32
	if(so > -1)
#else
	if(so != INVALID_SOCKET)
#endif
	{
		setError(false);
	if( svc )
  		svc->attach(this);
	}
	}
开发者ID:SiteView,项目名称:eccmeteor,代码行数:26,代码来源:socketport.cpp

示例3: networkWriter

uint16_t networkWriter(void *userdata, uint8_t *data, uint16_t length) {
	if(userdata == NULL) {
		return 0;
	}
	TCPSocket *tcps = (TCPSocket *)userdata;
	std::vector<uint8_t> buffer(data, data + length);
	boost::system::error_code ignored_error;
	ssize_t result = boost::asio::write(*(tcps->getSocket()), boost::asio::buffer(buffer), ignored_error);
	if(result < 0) {
		result = 0;
	}
	return (uint16_t)result;
}
开发者ID:timstableford,项目名称:LightweightRPC,代码行数:13,代码来源:TCPStreamConnector.cpp

示例4: init

void SocketPort::init(SocketService *svc,TCPSocket &tcp)
{
	Socket::init(accept(tcp.getSocket(),NULL,NULL));
	detect_pending = true;
	detect_output = false;
	detect_disconnect = true;

	next = prev = NULL;
	service = NULL;

	// FIXME: use macro here and in other files...
	if(so > -1)
	{
		setError(false);
    if( svc )
  		svc->attach(this);
	}
}
开发者ID:linuxemb,项目名称:source-code,代码行数:18,代码来源:socketport.cpp

示例5: networkReader

int16_t networkReader(void *userdata) {
	if(userdata == NULL) {
		return 0;
	}
	TCPSocket *tcps = (TCPSocket *)userdata;

	uint8_t data[1];
	ssize_t result = 0;
	try {
		result = boost::asio::read(*(tcps->getSocket()), boost::asio::buffer(data, 1));
	} catch (std::exception& e) {
		return -2;
	}
	if(result <= 0) {
		return -1;
	} else {
		return (uint16_t)data[0];
	}
}
开发者ID:timstableford,项目名称:LightweightRPC,代码行数:19,代码来源:TCPStreamConnector.cpp

示例6: connect

void TCPStream::connect(TCPSocket &tcpip)
{
    tpport_t port;

    endStream();
    family = IPV4;
    so = accept(tcpip.getSocket(), NULL, NULL);
    if(so == INVALID_SOCKET)
        return;

    IPV4Host host = getPeer(&port);
    if(!tcpip.onAccept(host, port)) {
        endSocket();
        iostream::clear(ios::failbit | rdstate());
        return;
    }

    segmentBuffering(tcpip.getSegmentSize());
    Socket::state = CONNECTED;
}
开发者ID:PipoloyJo,项目名称:ucommon,代码行数:20,代码来源:tcp.cpp

示例7: streambuf

TCPStream::TCPStream(TCPSocket &server, bool throwflag, timeout_t to) :
    streambuf(), Socket(accept(server.getSocket(), NULL, NULL))
    ,iostream((streambuf *)this)
    ,bufsize(0)
    ,gbuf(NULL)
    ,pbuf(NULL) {
    tpport_t port;
    family = IPV4;

    timeout = to;
    setError(throwflag);
    IPV4Host host = getPeer(&port);
    if(!server.onAccept(host, port)) {
        endSocket();
        error(errConnectRejected);
        iostream::clear(ios::failbit | rdstate());
        return;
    }

    segmentBuffering(server.getSegmentSize());
    Socket::state = CONNECTED;
}
开发者ID:darcyg,项目名称:ucommon,代码行数:22,代码来源:tcp.cpp

示例8: SocketUnknownHost

TCPSocket *TCPSocket::connect(const char *host, int port)
    throw(SocketUnknownHost, SocketConnectionRefused)
{
    TCPSocket *sock = new TCPSocket(::socket(AF_INET, SOCK_STREAM, 0));

    // Hostname resolution
    struct sockaddr_in address;
    struct hostent* h = ::gethostbyname(host);
    if(h == NULL)
        throw SocketUnknownHost();

    address.sin_family = AF_INET;
    address.sin_addr = *((struct in_addr *)h->h_addr);
    address.sin_port = htons(port);

    memset(&(address.sin_zero), 0, 8);

    if(::connect(sock->getSocket(), (struct sockaddr*)&address,
            sizeof(address)) == -1)
        throw SocketConnectionRefused();

    return sock;
}
开发者ID:remram44,项目名称:network,代码行数:23,代码来源:TCP.cpp


注:本文中的TCPSocket::getSocket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。