sockettwowaystream.cpp
来自「一个语言识别引擎」· C++ 代码 · 共 50 行
CPP
50 行
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
/*
* Copyright (C) 2006 Paul Fitzpatrick
* CopyPolicy: Released under the terms of the GNU GPL v2.0.
*
*/
#include <yarp/SocketTwoWayStream.h>
#include <ace/INET_Addr.h>
#include <ace/OS.h>
using namespace yarp;
int SocketTwoWayStream::open(const Address& address) {
if (address.getPort()==-1) {
return -1;
}
ACE_SOCK_Connector connector;
ACE_INET_Addr addr(address.getPort(),address.getName().c_str());
int result = connector.connect(stream,addr,0,ACE_Addr::sap_any,1);
if (result>=0) {
happy = true;
}
updateAddresses();
return result;
}
void SocketTwoWayStream::open(ACE_SOCK_Acceptor& acceptor) {
int result = acceptor.accept(stream);
if (result>=0) {
happy = true;
}
updateAddresses();
}
void SocketTwoWayStream::updateAddresses() {
int one = 1;
stream.set_option (ACE_IPPROTO_TCP, TCP_NODELAY, &one,
sizeof(int));
ACE_INET_Addr local, remote;
stream.get_local_addr(local);
stream.get_remote_addr(remote);
localAddress = Address(local.get_host_addr(),local.get_port_number());
remoteAddress = Address(remote.get_host_addr(),remote.get_port_number());
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?