// Exclude 3 static void show_codgram (void) { char buff[BUFSIZ]; size_t buflen = sizeof (buff); // Exclude 3 const ACE_TCHAR *peer = ACE_TEXT ("other_host:8042"); ACE_INET_Addr peer_addr (peer); ACE_SOCK_CODgram udp; if (0 != udp.open (peer_addr)) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), peer)); // ... if (-1 == udp.send (buff, buflen)) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("send"))); // Listing 3 }
int ACE_TMAIN (int argc , ACE_TCHAR *argv[]) { if(argc != 3) { ACE_DEBUG((LM_DEBUG, "Usage:\n %s [destination host] [destination port]\n\n", argv[0])); ACE_OS::exit(1); } char *buf = (char *)ACE_OS::malloc(20 * sizeof(char)); ACE_OS::strcpy(buf, "Hello"); ACE_SOCK_CODgram sock; ACE_INET_Addr raddr(ACE_OS::atoi(argv[2]), argv[1]); sock.open( raddr, ACE_Addr::sap_any, PF_INET, 0, 1); int opt=0; int ret =0, ret2=0; unsigned int i; for(i=0; i < 21; i++) { opt = dscp[i] << 2; ret = sock.set_option(IPPROTO_IP, IP_TOS, (int *)&opt, (int)sizeof(opt) ); if(ret == -1){ ACE_DEBUG((LM_DEBUG, "setsockopt error: %m\n")); } for (int j=0; j<3; j++) { ret2 = sock.send(buf, ACE_OS::strlen(buf)); if(ret2 == -1){ ACE_DEBUG((LM_DEBUG, "send error: %m\n")); } ACE_OS::printf("opt: %u dscp: %u, %s, setsockopt returned: %d, send returned: %d\n", opt, opt >> 2, dscp_char[i], ret, ret2); ACE_OS::sleep(1); } } ACE_OS::free(buf); return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { parse_args (argc, argv); ACE_INET_Addr sa (port_number, host_name); void *cp; char buf[BUFSIZ]; int n; ACE_SOCK_CODgram dc; if (dc.open (sa, ACE_Addr::sap_any) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1); // First send the name of the file as a datagram. iovec iov[2]; iov[0].iov_base = (char *) "filename: "; iov[0].iov_len = 11; iov[1].iov_base = (char *) file_name; iov[1].iov_len = ACE_OS::strlen (file_name); if (dc.send (iov, 2) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "send"), -1); ACE_SOCK_Stream sc; ACE_SOCK_Connector con; if (con.connect (sc, sa) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "connect"), -1); ACE_Mem_Map mmap (file_name); if (mmap (cp) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "mmap"), -1); // Next, send the file's contents. if (sc.send_n (cp, mmap.size ()) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "send_urg"), -1); if (sc.close_writer () == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "close_writer"), -1); if ((n = sc.recv_n (buf, sizeof buf)) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "recv"), -1); else ACE_OS::write (ACE_STDOUT, buf, n); return 0; }