本文整理汇总了C++中ACE_SOCK_Stream::send_n方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_SOCK_Stream::send_n方法的具体用法?C++ ACE_SOCK_Stream::send_n怎么用?C++ ACE_SOCK_Stream::send_n使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_SOCK_Stream
的用法示例。
在下文中一共展示了ACE_SOCK_Stream::send_n方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Connect
///
/// pretend a connection.
int YARPOutputSocketDgram::Connect (const YARPUniqueNameID& name, const YARPString& own_name)
{
ACE_UNUSED_ARG (name);
OSDataDgram& d = OSDATA(system_resources);
YARP_DBG(THIS_DBG) ((LM_DEBUG, "Pretending a connection to port %d on %s\n",
d._remote_addr.get_port_number(),
d._remote_addr.get_host_addr()));
ACE_Time_Value timeout (YARP_SOCK_TIMEOUT, 0);
ACE_SOCK_Stream stream;
int r = d._service_socket.connect (stream, d._remote_addr, &timeout);
if (r < 0)
{
ACE_DEBUG ((LM_ERROR, "cannot connect to remote peer %s:%d\n", d._remote_addr.get_host_addr(), d._remote_addr.get_port_number()));
return YARP_FAIL;
}
/// send the header.
int port_number = 0;
MyMessageHeader hdr;
hdr.SetGood ();
hdr.SetLength (YARP_MAGIC_NUMBER + 128*name.getRequireAck());
stream.send_n (&hdr, sizeof(hdr), 0);
/// fine, now send the name of the connection.
NetInt32 name_len = own_name.length();
stream.send_n (&name_len, sizeof(NetInt32), 0);
stream.send_n (own_name.c_str(), name_len, 0);
/// wait response.
hdr.SetBad ();
r = stream.recv (&hdr, sizeof(hdr), 0, &timeout);
if (r < 0)
{
stream.close ();
ACE_DEBUG ((LM_ERROR, "cannot handshake with remote %s:%d\n", d._remote_addr.get_host_addr(), d._remote_addr.get_port_number()));
return YARP_FAIL;
}
/// stores the remote acceptor address for future use (e.g. closing the connection).
d._remote_acceptor_store = d._remote_addr;
port_number = hdr.GetLength();
if (port_number == -1)
{
/// there might be a real -1 port number -> 65535.
stream.close ();
ACE_DEBUG ((LM_ERROR, "*** error, got garbage back from remote %s:%d\n", d._remote_addr.get_host_addr(), d._remote_addr.get_port_number()));
return YARP_FAIL;
}
/// the connect changes the remote port number to the actual assigned channel.
d._remote_addr.set_port_number (port_number);
stream.close ();
return YARP_OK;
}
示例2: handle
void
JAWS_Synch_IO::transmit_file (const char *filename,
const char *header,
int header_size,
const char *trailer,
int trailer_size)
{
ACE_Filecache_Handle handle (ACE_TEXT_CHAR_TO_TCHAR (filename));
int result = handle.error ();
if (result == ACE_Filecache_Handle::ACE_SUCCESS)
{
#if defined (ACE_JAWS_BASELINE) || defined (ACE_WIN32)
ACE_SOCK_Stream stream;
stream.set_handle (this->handle_);
if ((stream.send_n (header, header_size) == header_size)
&& (stream.send_n (handle.address (), handle.size ())
== handle.size ())
&& (stream.send_n (trailer, trailer_size) == trailer_size))
this->handler_->transmit_file_complete ();
else
result = -1;
#else
// Attempting to use writev
// Is this faster?
iovec iov[3];
int iovcnt = 0;
if (header_size > 0)
{
iov[iovcnt].iov_base = const_cast<char*> (header);
iov[iovcnt].iov_len = header_size;
iovcnt++;
}
if (handle.size () > 0)
{
iov[iovcnt].iov_base = reinterpret_cast<char*> (handle.address ());
iov[iovcnt].iov_len = handle.size ();
iovcnt++;
}
if (trailer_size > 0)
{
iov[iovcnt].iov_base = const_cast<char*> (trailer);
iov[iovcnt].iov_len = trailer_size;
iovcnt++;
}
if (ACE_OS::writev (this->handle_, iov, iovcnt) < 0)
result = -1;
else
this->handler_->transmit_file_complete ();
#endif /* ACE_JAWS_BASELINE */
}
if (result != ACE_Filecache_Handle::ACE_SUCCESS)
this->handler_->transmit_file_error (result);
}
示例3: sizeof
void
JAWS_Synch_IO::transmit_file (JAWS_IO_Handler *ioh,
ACE_HANDLE handle,
const char *header,
unsigned int header_size,
const char *trailer,
unsigned int trailer_size)
{
int result = 0;
if (handle != ACE_INVALID_HANDLE)
{
ACE_SOCK_Stream stream;
stream.set_handle (ioh->handle ());
if ((unsigned long) stream.send_n (header, header_size) < header_size)
{
result = -1;
}
else
{
int count;
char buf[BUFSIZ];
do
{
count = ACE_OS::read (handle, buf, sizeof (buf));
if (count <= 0)
break;
if (stream.send_n (buf, count) < count)
{
result = -1;
}
}
while (result == 0);
if ((unsigned long) stream.send_n (trailer, trailer_size)
< trailer_size)
{
result = -1;
}
}
}
if (result == 0)
ioh->transmit_file_complete ();
else
ioh->transmit_file_error (result);
}
示例4: factory_addr
int
FT_EventService::report_factory(CORBA::ORB_ptr orb,
FtRtecEventChannelAdmin::EventChannel_ptr ec)
{
try{
char* addr = ACE_OS::getenv("EventChannelFactoryAddr");
if (addr != 0) {
// instaniated by object factory, report my ior back to the factory
ACE_INET_Addr factory_addr(addr);
ACE_SOCK_Connector connector;
ACE_SOCK_Stream stream;
ORBSVCS_DEBUG((LM_DEBUG,"connecting to %s\n",addr));
if (connector.connect(stream, factory_addr) == -1)
ORBSVCS_ERROR_RETURN((LM_ERROR, "(%P|%t) Invalid Factory Address\n"), -1);
ORBSVCS_DEBUG((LM_DEBUG,"Factory connected\n"));
CORBA::String_var my_ior_string = orb->object_to_string(ec);
int len = ACE_OS::strlen(my_ior_string.in()) ;
if (stream.send_n(my_ior_string.in(), len) != len)
ORBSVCS_ERROR_RETURN((LM_ERROR, "(%P|%t) IOR Transmission Error\n"), -1);
stream.close();
}
}
catch (...){
return -1;
}
return 0;
}
示例5:
void
JAWS_Synch_IO_No_Cache::send_message (const char *buffer, int length)
{
ACE_SOCK_Stream stream;
stream.set_handle (this->handle_);
stream.send_n (buffer, length);
}
示例6: WriteData
///////////////////////////////////////////////////////////////////////////
// <summary>
// This method writes data from the given buffer to the underlying stream.
// It can block or not, depending on the value of the blocking parameter.
// </summary>
//
// <param name = "buffer">
// The buffer that contains the data to be written.
// </param>
//
// <param name = "size">
// The size of the buffer in bytes of the buffer.
// </param>
//
// <param name = "blocking">
// True if the write request should block; false otherwise.
// </param>
//
// <param name = "bytesWritten">
// An out parameter that will contain the number of bytes that have been
// written to the stream.
// </param>
//
// <returns>
// Returns a MgStreamStatus value indicating the status of the operation.
// </returns>
MgStreamHelper::MgStreamStatus MgAceStreamHelper::WriteData(void* buffer,
size_t size, bool blocking, size_t* bytesWritten)
{
// Do not attempt writing zero byte to the socket as this could be problematic.
if (0 == size)
{
return MgStreamHelper::mssDone;
}
ACE_ASSERT( buffer && size > 0 );
MgStreamHelper::MgStreamStatus stat = MgStreamHelper::mssError;
// check parameters
if ( buffer && size > 0 )
{
// init out parameter
if ( bytesWritten != NULL )
*bytesWritten = 0;
ACE_SOCK_Stream stream;
stream.set_handle( m_handle );
ssize_t res = 0;
// On Linux, use MSG_NOSIGNAL to request not to send SIGPIPE on
// errors on stream oriented sockets when the other end breaks
// the connection. The EPIPE error is still returned.
// Note that neither trapping the SIGPIPE signal via an
// ACE_Event_Handler nor calling ACE_OS::signal(SIGPIPE, SIG_IGN)
// seems to work.
if ( blocking )
{
res = stream.send_n(buffer, size, MG_MSG_NOSIGNAL);
}
else
{
res = stream.send(buffer, size, MG_MSG_NOSIGNAL);
}
// check for failure
if ( res >= 0 )
{
// update out parameter
if ( bytesWritten != NULL )
*bytesWritten = res;
if ( res == (ssize_t)size )
{
stat = MgStreamHelper::mssDone;
}
else
{
stat = blocking ? MgStreamHelper::mssError : MgStreamHelper::mssNotDone;
}
}
}
return stat;
}
示例7: main
int main(int argc, char* argv[]){
if (argc > 1){
return 1;
}
cout << argv[0] << endl;
ACE_INET_Addr addr(1234, ACE_LOCALHOST);
ACE_SOCK_Stream stream;
ACE_SOCK_Acceptor acceptor;
int success = acceptor.open(addr, 1);
ACE_TCHAR addrStr[20];
if (success > 0) {
addr.addr_to_string(addrStr, 20);
}
//*
success = acceptor.accept(stream);
if (success < 0) {
cout << "Cannot accept" << endl;
return 1;
}
//*/
char buf[BUFSIZ];
int n;
char *msg = "You are connected";
stream.send_n(msg, strlen(msg));
stream.close();
/*
while (stream.recv(buf, BUFSIZ)) {
// _write(1, buf, n);
cout << buf << endl;
}
//*/
cout << endl << "Done" << endl;
return 0;
}
示例8:
void
JAWS_Synch_IO::send_message (JAWS_IO_Handler *ioh,
const char *buffer,
unsigned int length)
{
ACE_SOCK_Stream stream;
stream.set_handle (ioh->handle ());
stream.send_n (buffer, length);
}
示例9: unmarshalledOctetServer
// thread function that serves the client for the UnMarshalled Octet
// test
static ACE_THR_FUNC_RETURN unmarshalledOctetServer (void *arg){
// unbundle the arguments
ArgStruct * args = reinterpret_cast<ArgStruct *> (arg);
ACE_SOCK_Stream * dataModeStream = args->stream;
ACE_CDR::ULong numIterations = args->numIters;
delete args;
// serve the client for numIterations synchronous invocations
do {
// READ A MESSAGE FROM THE CLIENT
size_t bt;
ACE_CDR::ULong msgBufSize=0;
// read the size of the buffer to follow
if ((dataModeStream->recv_n(&msgBufSize, ACE_CDR::LONG_SIZE, 0, &bt)) == -1)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("recv_n")),
0);
msgBufSize = ACE_NTOHL(msgBufSize);
// allocate the buffer for the message payload
ACE_CDR::Octet * msgBuf = 0;
ACE_NEW_RETURN(msgBuf,
ACE_CDR::Octet[msgBufSize],
0);
// read the buffer
if ((dataModeStream->recv_n(msgBuf, msgBufSize, 0, &bt)) == -1)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("recv_n")),
0);
// clean up the allocated buffer
delete[] msgBuf;
// SEND A REPLY TO THE CLIENT
// send back a 2 byte reply
ACE_CDR::Short reply;
if ((dataModeStream->send_n(&reply, ACE_CDR::SHORT_SIZE, 0, &bt)) == -1)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("send_n")),
0);
} while (--numIterations);
// close and destroy the stream
dataModeStream->close();
delete dataModeStream;
return 0;
}
示例10: while
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
ACE_LOG_MSG->open (argv[0]);
parse_args (argc, argv);
// Default is to ask the server for ``help.''
static char buf[BUFSIZ] = "help\n";
int n;
ACE_SOCK_Stream sc;
ACE_SOCK_Connector con;
if (con.connect (sc,
ACE_INET_Addr (port_number,
host_name)) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n%a",
"connect",
1),
-1);
if (remote_reconfigure)
// Remotely instruct the server to reconfigure itself.
ACE_OS::strcpy (buf, "reconfigure\n");
// Send the command.
if (sc.send_n (buf,
ACE_OS::strlen (buf) + 1) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n%a",
"send",
1), -1);
// Next, read the response.
while ((n = sc.recv (buf,
sizeof buf)) > 0)
if (ACE_OS::write (ACE_STDOUT,
buf,
n) != n)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n%a",
"write",
1),
-1);
if (sc.close () == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n%a",
"close",
1),
-1);
return 0;
}
示例11: send_data
static void* send_data(void *)
{
while(1)
{
std::cout<<">>Hello World"<<std::endl;
Peer->send_n("Hello World", sizeof("Hello World"));
ACE_OS::sleep(1);
}
return 0;
}
示例12: Close
int YARPOutputSocketDgram::Close (const YARPUniqueNameID& name)
{
ACE_Time_Value timeout (YARP_SOCK_TIMEOUT, 0);
ACE_UNUSED_ARG (name);
OSDataDgram& d = OSDATA(system_resources);
YARP_DBG(THIS_DBG) ((LM_DEBUG, "Pretending to close a connection to port %d on %s\n",
d._remote_addr.get_port_number(),
d._remote_addr.get_host_addr()));
/// send the header.
MyMessageHeader hdr;
hdr.SetGood ();
hdr.SetLength (YARP_MAGIC_NUMBER + 1);
ACE_SOCK_Stream stream;
int r = d._service_socket.connect (stream, d._remote_addr, &timeout);
if (r < 0)
{
ACE_DEBUG ((LM_DEBUG, "cannot connect to remote peer %s:%d\n", d._remote_addr.get_host_addr(), d._remote_addr.get_port_number()));
ACE_DEBUG ((LM_DEBUG, "close will complete anyway\n"));
d._connector_socket.close ();
identifier = ACE_INVALID_HANDLE;
return YARP_FAIL;
}
r = stream.send_n (&hdr, sizeof(hdr), 0);
/// wait response.
/// need a timeout here!
hdr.SetBad ();
r = stream.recv (&hdr, sizeof(hdr), 0, &timeout);
if (r < 0)
{
stream.close ();
d._connector_socket.close ();
identifier = ACE_INVALID_HANDLE;
ACE_DEBUG ((LM_DEBUG, "cannot handshake with remote %s:%d\n", d._remote_addr.get_host_addr(), d._remote_addr.get_port_number()));
return YARP_FAIL;
}
hdr.GetLength();
d._remote_addr.set ((u_short)0);
d._remote_acceptor_store.set ((u_short)0);
stream.close ();
d._connector_socket.close ();
identifier = ACE_INVALID_HANDLE;
return YARP_OK;
}
示例13: remote_sap
int
Scavenger_Task::svc(void)
{
this->the_barrier_->wait ();
ACE_DEBUG ((LM_DEBUG, "(%P|%t) Starting scavenger thread\n"));
ACE_SOCK_Stream stream;
{
ACE_INET_Addr remote_sap (this->endpoint_);
ACE_SOCK_Connector connector;
if (connector.connect(stream, remote_sap) == -1)
{
ACE_ERROR((LM_ERROR, "Cannot connect to <%s>\n", endpoint_));
return -1;
}
}
for (;;)
{
ACE_Time_Value period (0, this->period_in_usecs_);
ACE_OS::sleep (period);
{
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
if (this->stopped_)
break;
}
ACE_hrtime_t start = ACE_OS::gethrtime ();
ssize_t n = stream.send_n(&start, sizeof(start));
if (n == 0 || n == -1)
break;
ACE_hrtime_t end;
n = stream.recv(&end, sizeof(end));
if (n == 0 || n == -1)
break;
if (start != end)
{
ACE_ERROR((LM_ERROR,
"Mismatched response from <%s>\n", endpoint_));
break;
}
}
stream.close();
ACE_DEBUG ((LM_DEBUG, "(%P|%t) Finishing scavenger thread\n"));
return 0;
}
示例14: addr
static ACE_THR_FUNC_RETURN
worker (void *)
{
ACE_OS::sleep (3);
const ACE_TCHAR *msg = ACE_TEXT ("Message from Connection worker");
ACE_TCHAR buf [BUFSIZ];
buf[0] = static_cast<ACE_TCHAR> ((ACE_OS::strlen (msg) + 1));
ACE_OS::strcpy (&buf[1], msg);
ACE_INET_Addr addr (rendezvous);
ACE_DEBUG((LM_DEBUG,
"(%t) Spawning %d client threads...\n",
cli_thrno));
int grp = ACE_Thread_Manager::instance ()->spawn_n (cli_thrno,
&cli_worker,
buf);
ACE_TEST_ASSERT (grp != -1);
ACE_Thread_Manager::instance ()->wait_grp (grp);
ACE_DEBUG ((LM_DEBUG,
"(%t) Client threads done; shutting down...\n"));
ACE_SOCK_Stream stream;
ACE_SOCK_Connector connect;
if (connect.connect (stream, addr) == -1)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%t) %p Error while connecting\n"),
ACE_TEXT ("connect")));
const ACE_TCHAR *sbuf = ACE_TEXT ("\011shutdown");
ACE_DEBUG ((LM_DEBUG,
"shutdown stream handle = %x\n",
stream.get_handle ()));
if (stream.send_n (sbuf, (ACE_OS::strlen (sbuf) + 1) * sizeof (ACE_TCHAR)) == -1)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("send_n")));
ACE_DEBUG ((LM_DEBUG,
"Sent message of length = %d\n",
ACE_OS::strlen (sbuf)));
stream.close ();
return 0;
}
示例15: sendMessage
int Sender::sendMessage(const std::string& str, const ACE_SOCK_Stream& stream, bool quiet) {
ssize_t res = stream.send_n(str.c_str(), (int)str.size(), &timeout);
if(res != (ssize_t)str.size()) {
if(!quiet)
cerr << "Sender::sendMessage(): sending timeout!"<<endl;
return E_SEND;
}
res = stream.recv(response, 1, &timeout);
if(res <= 0) {
if(!quiet)
cerr << "Sender::sendMessage(): response timeout!" << endl;
return E_RESPONSE;
}
return SUCCESS;
}