本文整理汇总了C++中ACE_SOCK_Dgram::send方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_SOCK_Dgram::send方法的具体用法?C++ ACE_SOCK_Dgram::send怎么用?C++ ACE_SOCK_Dgram::send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_SOCK_Dgram
的用法示例。
在下文中一共展示了ACE_SOCK_Dgram::send方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle_timeout
int DgramHandler::handle_timeout (const ACE_Time_Value ¤t_time, const void *act)
{
ACE_UNUSED_ARG (current_time);
ACE_UNUSED_ARG (act);
int sendBuffer = 0;
if (++timeoutsTriggered_ >= expectedTriggers_)
reactor ()->cancel_timer (this, 1);
ACE_SOCK_Dgram socket;
if (-1 == socket.open (ACE_INET_Addr (static_cast< u_short > (0),
static_cast< ACE_UINT32 > (INADDR_ANY)),
ACE_PROTOCOL_FAMILY_INET, 0, 1))
ACE_ERROR ((LM_ERROR,
ACE_TEXT (" (%P) %p\n"),
ACE_TEXT ("Cannot open socket for sending Qt dgrams")));
ACE_INET_Addr peerAddr;
peer_.get_local_addr (peerAddr);
if (sizeof (sendBuffer) != socket.send (&sendBuffer,
sizeof (sendBuffer), peerAddr))
ACE_ERROR ((LM_ERROR,
ACE_TEXT (" (%P) %p\n"),
ACE_TEXT ("Cannot send dgram")));
else
++dgramsSent_;
socket.close ();
return 0;
}
示例2: send_dgram
int send_dgram (ACE_SOCK_Dgram &socket, ACE_INET_Addr addr, int done = 0)
{
// Send each message twice, once to the right port, and once to the "wrong"
// port. This helps generate noise and lets us see if port filtering is
// working properly.
const char *address = addr.get_host_addr ();
int port = addr.get_port_number ();
for (int i = 0; i < 2; ++i)
{
char buf[MAX_STRING_SIZE];
if (done)
buf[0] = 0;
else
ACE_OS::sprintf (buf, "%s/%d", address, port);
if (socket.send (buf, ACE_OS::strlen (buf),addr) == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Send to %C, %p\n"),
address,
ACE_TEXT ("send_dgram - error calling send on ")
ACE_TEXT ("ACE_SOCK_Dgram.")), -1);
addr.set_port_number (++port);
}
return 0;
}
示例3: echo_dgram
// Listing 2 code/ch09
void echo_dgram (void)
{
ACE_INET_Addr my_addr (ACE_static_cast (u_short, 10102));
ACE_INET_Addr your_addr;
ACE_SOCK_Dgram udp (my_addr);
char buff[BUFSIZ];
size_t buflen = sizeof (buff);
ssize_t recv_cnt = udp.recv (buff, buflen, your_addr);
if (recv_cnt > 0)
udp.send (buff, ACE_static_cast (size_t, buflen), your_addr);
udp.close ();
return;
}
示例4: send_unicast
int send_unicast (const ACE_INET_Addr &to)
{
const char *message = "this is the message!\n";
ACE_INET_Addr my_addr (ACE_static_cast (u_short, 10101));
ACE_SOCK_Dgram udp (my_addr);
ssize_t sent = udp.send (message,
ACE_OS_String::strlen (message) + 1,
to);
udp.close ();
if (sent == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
ACE_TEXT ("send")), -1);
return 0;
}
示例5: mutex
static void
writer (void)
{
ACE_RW_Process_Mutex mutex (mutex_name.c_str ());
// Make sure the constructor succeeded
if (ACE_LOG_MSG->op_status () != 0)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Writer, mutex %s %p\n"),
mutex_name.c_str (),
ACE_TEXT ("ctor")));
return;
}
ACE_SOCK_Dgram sock;
ACE_INET_Addr parent;
parent.set (reporting_port, ACE_LOCALHOST, 1, AF_INET);
ACE_TCHAR me_str[80];
parent.addr_to_string (me_str, 80);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Sending reports to %s\n"), me_str));
if (sock.open (ACE_Addr::sap_any, PF_INET) == -1)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("UDP open")));
Range_Report report;
report.child_ = 0; // We're the writer
ACE_Time_Value start (ACE_Time_Value::zero), stop (ACE_Time_Value::zero);
// Grab the lock
if (-1 == mutex.acquire_write ())
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Writer first %p\n"),
ACE_TEXT ("acquire_write")));
else
{
start = ACE_OS::gettimeofday ();
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer acquired first time\n")));
}
// Now sleep, making the readers wait for the lock. Then release the lock,
// sleep, and reacquire the lock.
ACE_OS::sleep (2);
stop = ACE_OS::gettimeofday ();
if (-1 == mutex.release ())
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Writer %p\n"),
ACE_TEXT ("first release")));
else
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Writer released first time\n")));
report.range_.set (start, stop);
ssize_t bytes = sock.send (&report, sizeof (report), parent);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer sent %b byte report\n"), bytes));
ACE_OS::sleep (1); // Ensure we don't immediately grab the lock back
start = stop = ACE_Time_Value::zero;
if (-1 == mutex.acquire_write ())
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Writer second %p\n"),
ACE_TEXT ("acquire_write")));
else
{
start = ACE_OS::gettimeofday ();
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer acquired second time\n")));
}
ACE_OS::sleep (2);
stop = ACE_OS::gettimeofday ();
if (-1 == mutex.release ())
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Writer %p\n"),
ACE_TEXT ("second release")));
else
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Writer released second time\n")));
report.range_.set (start, stop);
bytes = sock.send (&report, sizeof (report), parent);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer sent %b byte report\n"), bytes));
sock.close ();
return;
}
示例6: start
//.........这里部分代码省略.........
ACE_OS::sleep (1);
ACE_SOCK_Dgram sock;
ACE_INET_Addr parent;
parent.set (reporting_port, ACE_LOCALHOST, 1, AF_INET);
ACE_TCHAR me_str[80];
parent.addr_to_string (me_str, 80);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Sending reports to %s\n"), me_str));
if (sock.open (ACE_Addr::sap_any, PF_INET) == -1)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("UDP open")));
Range_Report report;
report.child_ = num;
ACE_Time_Value start (ACE_Time_Value::zero), stop (ACE_Time_Value::zero);
ACE_RW_Process_Mutex mutex (mutex_name.c_str ());
// Make sure the constructor succeeded
if (ACE_LOG_MSG->op_status () != 0)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Reader %d, mutex %s %p\n"),
num,
mutex_name.c_str (),
ACE_TEXT ("ctor")));
return;
}
ACE_OS::sleep (num);
// Grab the lock
if (-1 == mutex.acquire_read ())
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Reader %d %p\n"),
num,
ACE_TEXT ("first acquire_read")));
else
{
start = ACE_OS::gettimeofday ();
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Reader %d acquired first time\n"),
num));
}
// Wait a bit, then release and report the range held.
ACE_OS::sleep (num);
// Release the lock then wait; in the interim, the writer should change
// the file.
stop = ACE_OS::gettimeofday ();
if (-1 == mutex.release ())
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Reader %d %p\n"),
num,
ACE_TEXT ("first release")));
else
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Reader %d released first time\n"), num));
report.range_.set (start, stop);
ssize_t bytes = sock.send (&report, sizeof (report), parent);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Reader %d sent %b byte report\n"),
num,
bytes));
ACE_OS::sleep (4 - num);
start = stop = ACE_Time_Value::zero;
if (-1 == mutex.acquire_read ())
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Reader %d %p\n"),
num,
ACE_TEXT ("second acquire_read")));
else
{
start = ACE_OS::gettimeofday ();
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Reader %d acquired second time\n"),
num));
}
// Done; small delay, release, report, and return.
ACE_OS::sleep (1);
stop = ACE_OS::gettimeofday ();
if (-1 == mutex.release ())
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Reader %d %p\n"),
num,
ACE_TEXT ("second release")));
else
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Reader %d released second time; done\n"),
num));
report.range_.set (start, stop);
bytes = sock.send (&report, sizeof (report), parent);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Reader %d sent %b byte report\n"),
num,
bytes));
sock.close ();
return;
}