本文整理汇总了C++中ACE_SOCK_Stream::sendv_n方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_SOCK_Stream::sendv_n方法的具体用法?C++ ACE_SOCK_Stream::sendv_n怎么用?C++ ACE_SOCK_Stream::sendv_n使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_SOCK_Stream
的用法示例。
在下文中一共展示了ACE_SOCK_Stream::sendv_n方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
int logClient::process(ACE_CString* s){
ACE_SOCK_Stream logger;
ACE_SOCK_Connector connector;
ACE_INET_Addr addr(9876, "127.0.0.1");
if(connector.connect(logger, addr) == -1){
ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%p \n"), ACE_TEXT("open")), -1);
}
ACE_Log_Record record(LM_DEBUG,
ACE_OS::time ((time_t *) 0),
ACE_OS::getpid());
record.msg_data(s.c_str());
const size_t max_payload_size =
4
+ 8
+ 4
+ 4
+ ACE_Log_Record::MAXLOGMSGLEN
+ ACE_CDR::MAX_ALIGNMENT;
ACE_OutputCDR payload(max_payload_size);
payload<< record;
ACE_CDR::ULong length =
ACE_Utils::truncate_cast<ACE_CDR::ULong> (payload.total_length());
ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8);
header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER);
header << ACE_CDR::ULong(length);
iovec iov[2];
iov[0].iov_base = header.begin() -> rd_ptr();
iov[0].iov_len = 8;
iov[1].iov_base = payload.begin() -> rd_ptr();
iov[1].iov_len = length;
if (logger.sendv_n(iov, 2) == -1)
ACE_ERROR_RETURN((LM_ERROR,"%p\n","send"), -1);
/*
*/
ACE_Message_Block* header_p;
auto_ptr<ACE_Message_Block> header(header_p);
ACE_CDR::mb_align(header.get());
ACE_Message_Block* payload_p;
ssize_t count = logger.recv_n(header->wr_ptr(),8);
switch(count){
default:
case -1:
case 0:
case 8:
break;
}
header->wr_ptr(8);
}
示例2: main
int main(int argc, char** argv)
{
const char* pathname = argc > 1 ? argv[1] : "/index.html";
const char* server_hostname = argc > 2 ? argv[2] : "ace.ece.uci.edu";
// Add funcation call for demo.
dummy();
ACE_SOCK_Connector connector;
ACE_SOCK_Stream peer;
ACE_INET_Addr peer_addr;
if (-1 == peer_addr.set(80, server_hostname))
{
log("peer_addr.set failed\n");
return 1;
}
else if (-1 == connector.connect(peer, peer_addr))
{
log("connector.connect failed\n");
return 1;
}
char buf[BUFSIZ];
iovec iov[3];
iov[0].iov_base = (void*)"GET ";
iov[0].iov_len = 4;
iov[1].iov_base = (void*)pathname;
iov[1].iov_len = strlen(pathname);
iov[2].iov_base = (void*)" HTTP/1.0\r\n\r\n";
iov[2].iov_len = 13;
if (-1 == peer.sendv_n(iov, 3))
{
log("peer.sendv_v failed\n");
return 1;
}
for (ssize_t n = 0; (n = peer.recv(buf, sizeof(buf))) > 0; )
{
ACE::write_n(ACE_STDOUT, buf, n);
}
return peer.close();
}
示例3: send
//FUZZ: disable check_for_lack_ACE_OS
int send (const ACE_Log_Record &log_record) {
//FUZZ: enable check_for_lack_ACE_OS
// Serialize the log record using a CDR stream, allocate
// enough space for the complete <ACE_Log_Record>.
const size_t max_payload_size =
4 // type()
+ 8 // timestamp
+ 4 // process id
+ 4 // data length
+ ACE_Log_Record::MAXLOGMSGLEN // data
+ ACE_CDR::MAX_ALIGNMENT; // padding;
// Insert contents of <log_record> into payload stream.
ACE_OutputCDR payload (max_payload_size);
payload << log_record;
// Get the number of bytes used by the CDR stream.
ACE_CDR::ULong length = payload.total_length ();
// Send a header so the receiver can determine the byte
// order and size of the incoming CDR stream.
ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8);
header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER);
// Store the size of the payload that follows
header << ACE_CDR::ULong (length);
// Use an iovec to send both buffer and payload simultaneously.
iovec iov[2];
iov[0].iov_base = header.begin ()->rd_ptr ();
iov[0].iov_len = 8;
iov[1].iov_base = payload.begin ()->rd_ptr ();
iov[1].iov_len = length;
// Send header and payload efficiently using "gather-write".
return logging_peer_.sendv_n (iov, 2);
}
示例4: runUnmarshalledOctetTest
// conduct the UnMarshalled Octet performance test using separate
// send_n calls with Nagle's algorithm disabled
ACE_SCTP::HIST runUnmarshalledOctetTest(ACE_CDR::Octet *buf, size_t seqLen, ACE_SOCK_Stream & stream){
ACE_CDR::ULong const testIterations = Options_Manager::test_iterations;
size_t bt;
ACE_CDR::ULong cnt = 0;
// variables for the timing measurements
ACE_hrtime_t startTime, endTime;
ACE_CDR::Double messageLatency_usec = 0.0;
ACE_CDR::ULong msgLen = seqLen*ACE_CDR::OCTET_SIZE;
// explicity configure Nagling. Default is
// Options_Manager::test_enable_nagle=0 so default configurations is
// NO NAGLING
ACE_CDR::Long nagle;
if (Options_Manager::test_enable_nagle)
nagle=0;
else
nagle=1;
if (Options_Manager::test_transport_protocol == IPPROTO_SCTP){
// default - sctp case
if (-1 == stream.set_option(IPPROTO_SCTP, SCTP_NODELAY, &nagle, sizeof nagle))
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"set_option"),
0);
} else {
// tcp case
if (-1 == stream.set_option(IPPROTO_TCP, TCP_NODELAY, &nagle, sizeof nagle))
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"set_option"),
0);
}
// prime the client and server before starting the test
for(cnt=0;cnt<primerIterations;++cnt){
// send message size
// TODO : The message length should be CDR encoded
ACE_CDR::ULong msgLenExpressed = ACE_HTONL(msgLen);
if (-1 == stream.send_n (&msgLenExpressed, ACE_CDR::LONG_SIZE, 0, &bt))
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"send_n"),
0);
// send a message
if (-1 == stream.send_n (buf, msgLen, 0, &bt))
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"send_n"),
0);
// block for a Short reply
ACE_CDR::Short reply;
if ((stream.recv_n(&reply, ACE_CDR::SHORT_SIZE, 0, &bt)) == -1)
ACE_ERROR_RETURN((LM_ERROR,
"%p\n",
"recv_n"),
0);
}
// AFTER PRIMING THE PUMP CREATE THE HISTOGRAM
ACE_SCTP::HIST aceStream_hist = 0;
aceStream_hist = createHistogram(msgLen);
if (0 == aceStream_hist)
ACE_ERROR_RETURN((LM_ERROR,
"%p\n",
"histogram create failed"),
0);
iovec iov[2];
// PERFORMANCE TEST LOOP
for (cnt = 0; cnt < testIterations; ++cnt){
// get the start time
startTime = ACE_OS::gethrtime();
if (!startTime)
ACE_ERROR_RETURN((LM_ERROR,
"%p\n",
"ACE_OS::gethrtime()"),
0);
ACE_CDR::ULong msgLenExpressed = ACE_HTONL(msgLen);
iov[0].iov_base = reinterpret_cast<char *> (&msgLenExpressed);
iov[0].iov_len = ACE_CDR::LONG_SIZE;
iov[1].iov_base = reinterpret_cast<char *> (buf);
iov[1].iov_len = msgLen;
if (-1 == stream.sendv_n (iov, 2))
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"send_n"),
0);
// block for a Short reply
//.........这里部分代码省略.........
示例5: if
//.........这里部分代码省略.........
} catch (const IORTable::NotFound&) {
ACE_ERROR_RETURN((LM_ERROR,
"InfoRepoMulticastResponder::handle_input() Object key not found\n"),
0);
}
ior = ior_result;
}
// Reply to the multicast message.
ACE_SOCK_Connector connector;
ACE_INET_Addr peer_addr;
ACE_SOCK_Stream stream;
peer_addr.set(remote_addr);
peer_addr.set_port_number(ACE_NTOHS(remote_port));
#if defined (ACE_HAS_IPV6)
if (peer_addr.is_linklocal()) {
// If this is one of our local linklocal interfaces this is not going
// to work.
// Creating a connection using such interface to the client listening
// at the IPv6 ANY address is not going to work (I'm not quite sure why
// but it probably has to do with the rather restrictive routing rules
// for linklocal interfaces).
// So we see if this is one of our local interfaces and if so create the
// connection using the IPv6 loopback address instead.
ACE_INET_Addr peer_tmp(peer_addr);
peer_tmp.set_port_number(static_cast<u_short>(0));
ACE_INET_Addr* tmp = 0;
size_t cnt = 0;
int err = ACE::get_ip_interfaces(cnt, tmp);
if (err == 0) {
for (size_t i = 0; i < cnt; ++i) {
if (peer_tmp == tmp[i]) {
peer_addr.set(ACE_NTOHS(remote_port),
ACE_IPV6_LOCALHOST);
break;
}
}
delete[] tmp;
}
}
#endif /* ACE_HAS_IPV6 */
if (OpenDDS::DCPS::DCPS_debug_level > 0) {
ACE_TCHAR addr[64];
peer_addr.addr_to_string(addr, sizeof(addr));
ACE_DEBUG((LM_DEBUG,
"(%P|%t) Replying to peer %s.\n",
addr));
}
// Connect.
if (connector.connect(stream, peer_addr) == -1)
ACE_ERROR_RETURN((LM_ERROR, "InfoRepoMulticastResponder::connect failed\n"), 0);
// Send the IOR back to the client. (Send iovec, which contains ior
// length as the first element, and ior itself as the second.)
// Length of ior to be sent.
CORBA::Short data_len =
static_cast<CORBA::Short>(ACE_HTONS(ior.length() + 1));
// Vector to be sent.
const int cnt = 2;
iovec iovp[cnt];
// The length of ior to be sent.
iovp[0].iov_base = (char *) &data_len;
iovp[0].iov_len = sizeof(CORBA::Short);
// The ior.
iovp[1].iov_base = const_cast<char*>(ior.c_str());
iovp[1].iov_len = static_cast<u_long>(ior.length() + 1);
ssize_t result = stream.sendv_n(iovp, cnt);
// Close the stream.
stream.close();
// Check for error.
if (result == -1)
ACE_ERROR_RETURN((LM_ERROR, "InfoRepoMulticastResponder::send failed\n"), 0);
if (OpenDDS::DCPS::DCPS_debug_level > 0)
ACE_DEBUG((LM_DEBUG,
"(%P|%t) InfoRepoMulticastResponder::handle_input() ior: <%C>\n"
"sent to %C:%u.\n"
"result from send = %d\n",
ior.c_str(),
peer_addr.get_host_name(),
peer_addr.get_port_number(),
result));
return 0;
}
示例6: addr
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
const ACE_TCHAR *logger_host = argc > 1 ? argv[1] : LOGGER_HOST;
u_short logger_port = argc > 2 ? ACE_OS::atoi (argv[2]) : LOGGER_PORT;
int max_iterations = argc > 3 ? ACE_OS::atoi (argv[3]) : MAX_ITERATIONS;
ACE_SOCK_Stream logger;
ACE_SOCK_Connector connector;
ACE_INET_Addr addr (logger_port, logger_host);
if (connector.connect (logger, addr) == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1);
for (int i = 0; i < max_iterations; i++)
{
ACE_Log_Record log_record (LM_DEBUG,
ACE_OS::time ((time_t *) 0),
ACE_OS::getpid ());
ACE_TCHAR buf[BUFSIZ];
ACE_OS::sprintf (buf, ACE_TEXT ("message = %d\n"), i + 1);
log_record.msg_data (buf);
const size_t max_payload_size =
4 // type()
+ 8 // timestamp
+ 4 // process id
+ 4 // data length
+ ACE_Log_Record::MAXLOGMSGLEN // data
+ ACE_CDR::MAX_ALIGNMENT; // padding;
// Insert contents of <log_record> into payload stream.
ACE_OutputCDR payload (max_payload_size);
payload << log_record;
// Get the number of bytes used by the CDR stream.
ACE_CDR::ULong length =
ACE_Utils::truncate_cast<ACE_CDR::ULong> (payload.total_length ());
// Send a header so the receiver can determine the byte order and
// size of the incoming CDR stream.
ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8);
header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER);
// Store the size of the payload that follows
header << ACE_CDR::ULong (length);
// Use an iovec to send both buffer and payload simultaneously.
iovec iov[2];
iov[0].iov_base = header.begin ()->rd_ptr ();
iov[0].iov_len = 8;
iov[1].iov_base = payload.begin ()->rd_ptr ();
iov[1].iov_len = length;
if (logger.sendv_n (iov, 2) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "send"), -1);
}
if (logger.close () == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("close")), -1);
return 0;
}
示例7: ExecuteUrl
bool OrkHttpClient::ExecuteUrl(const CStdString& request, CStdString& response, const CStdString& hostname, const int tcpPort, int timeout)
{
CStdString logMsg;
response = "";
ACE_SOCK_Connector connector;
ACE_SOCK_Stream peer;
ACE_INET_Addr peer_addr;
if(timeout < 1){timeout = 1;}
ACE_Time_Value aceTimeout (timeout);
CStdString requestDetails;
requestDetails.Format("timeout:%d http://%s:%d/%s", timeout, hostname, tcpPort, request);
time_t beginRequestTimestamp = time(NULL);
char szTcpPort[10];
sprintf(szTcpPort, "%d", tcpPort);
iovec iov[8];
iov[0].iov_base = (IOV_TYPE)"GET ";
iov[0].iov_len = 4; // Length of "GET ".
iov[1].iov_base = (PSTR)(PCSTR)request;
iov[1].iov_len = request.size();
iov[2].iov_base = (IOV_TYPE)" HTTP/1.0\r\n";
iov[2].iov_len = 11;
iov[3].iov_base = (IOV_TYPE)"Host: ";
iov[3].iov_len = 6;
iov[4].iov_base = (PSTR)(PCSTR)hostname;
iov[4].iov_len = hostname.size();
iov[5].iov_base = (IOV_TYPE)":";
iov[5].iov_len = 1;
iov[6].iov_base = szTcpPort;
iov[6].iov_len = strlen(szTcpPort);
iov[7].iov_base = (IOV_TYPE)"\r\n\r\n";
iov[7].iov_len = 4;
if (peer_addr.set (tcpPort, (PCSTR)hostname) == -1)
{
logMsg.Format("peer_addr.set() errno=%d %s", errno, requestDetails);
LogError(logMsg);
return false;
}
else if (connector.connect (peer, peer_addr, &aceTimeout) == -1)
{
if (errno == ETIME)
{
}
logMsg.Format("connector.connect() errno=%d %s", errno, requestDetails);
LogError(logMsg);
return false;
}
else if (peer.sendv_n (iov, 8, &aceTimeout) == -1)
{
logMsg.Format("peer.sendv_n errno=%d %s", errno, requestDetails);
LogError(logMsg);
return false;
}
ssize_t numReceived = 0;
#define BUFSIZE 4096
char buf [BUFSIZE];
CStdString header;
bool gotHeader = false;
while ( ((numReceived = peer.recv (buf, BUFSIZE, &aceTimeout)) > 0) && ((time(NULL) - beginRequestTimestamp) <= timeout) )
{
for(int i=0; i<numReceived; i++)
{
if(!gotHeader)
{
// extract header (delimited by CR-LF-CR-LF)
header += buf[i];
size_t headerSize = header.size();
if (headerSize > 4 &&
header.GetAt(headerSize-1) == '\n' &&
header.GetAt(headerSize-2) == '\r' &&
header.GetAt(headerSize-3) == '\n' &&
header.GetAt(headerSize-4) == '\r' )
{
gotHeader = true;
}
}
else
{
// extract content
response += buf[i];
}
}
}
peer.close();
logMsg.Format("%s:%d response:%s",hostname, tcpPort, response);
LOG4CXX_DEBUG(m_log, logMsg);
if(numReceived < 0)
{
logMsg.Format("numReceived:%d %s", numReceived, requestDetails);
LogError(logMsg);
return false;
}
if(header.size() > 15 && header.GetAt(9) == '4' && header.GetAt(10) == '0' && header.GetAt(11) == '0')
{
logMsg.Format("HTTP header:%s ** request:%s\nIgnore this message", header, requestDetails);
LOG4CXX_ERROR(m_log, logMsg);
//.........这里部分代码省略.........