| 1 |
ab11 |
1.1 |
// tdinwrite.cc. Test for -*- C++ -*- socket library |
| 2 |
|
|
// Copyright (C) 1992,1993,1994 Gnanasekaran Swaminathan <gs4t@virginia.edu> |
| 3 |
|
|
// |
| 4 |
|
|
// Permission is granted to use at your own risk and distribute this software |
| 5 |
|
|
// in source and binary forms provided the above copyright |
| 6 |
|
|
// notice and this paragraph are preserved on all copies. |
| 7 |
|
|
// This software is provided "as is" with no express or implied warranty. |
| 8 |
|
|
// |
| 9 |
|
|
// Version: 17Oct95 1.10 |
| 10 |
|
|
|
| 11 |
|
|
#include <sockinet.h> |
| 12 |
|
|
#include <stdlib.h> |
| 13 |
|
|
#include <unistd.h> |
| 14 |
|
|
|
| 15 |
|
|
int main(int ac, char** av) |
| 16 |
|
|
{ |
| 17 |
|
|
if (ac < 3) { |
| 18 |
|
|
cerr << "USAGE: " << av[0] << " thostname port-number " |
| 19 |
|
|
<< "data ... " << endl; |
| 20 |
|
|
return 1; |
| 21 |
|
|
} |
| 22 |
|
|
|
| 23 |
|
|
osockinet osin (sockbuf::sock_dgram); |
| 24 |
|
|
|
| 25 |
|
|
osin->connect (av[1], atoi (av[2])); |
| 26 |
|
|
|
| 27 |
|
|
cout << "local: " << osin->localport() << ' ' << osin->localhost() << endl |
| 28 |
|
|
<< "peer: " << osin->peerport() << ' ' << osin->peerhost() << endl; |
| 29 |
|
|
|
| 30 |
|
|
// test socket options |
| 31 |
|
|
cout << "socket type = " << osin->gettype() << endl; |
| 32 |
|
|
cout << "socket linger time = " << osin->linger(10) << endl; |
| 33 |
|
|
cout << "socket linger time = " << osin->linger(0) << endl; |
| 34 |
|
|
cout << "socket linger time = " << osin->linger() << endl; |
| 35 |
|
|
// cout << "socket send bufsz = " << osin->sendbufsz() << endl; |
| 36 |
|
|
// cout << "socket recv bufsz = " << osin->recvbufsz() << endl; |
| 37 |
|
|
cout << "socket keepalive = " << osin->keepalive(1) << endl; |
| 38 |
|
|
cout << "socket keepalive = " << osin->keepalive(0) << endl; |
| 39 |
|
|
cout << "socket clearerror = " << osin->clearerror() << endl; |
| 40 |
|
|
cout << "socket debug = " << osin->debug(1) << endl; |
| 41 |
|
|
cout << "socket debug = " << osin->debug(0) << endl; |
| 42 |
|
|
cout << "socket reuse = " << osin->reuseaddr(1) << endl; |
| 43 |
|
|
cout << "socket reuse = " << osin->reuseaddr(0) << endl; |
| 44 |
|
|
|
| 45 |
|
|
#ifdef __linux__ |
| 46 |
|
|
int timeo = 0; |
| 47 |
|
|
osin->getopt(sockbuf::so_sndtimeo, &timeo, sizeof(timeo)); |
| 48 |
|
|
cout << "socket sendtimeo = " << timeo << endl; |
| 49 |
|
|
osin->getopt(sockbuf::so_rcvtimeo, &timeo, sizeof(timeo)); |
| 50 |
|
|
cout << "socket recvtimeo = " << timeo << endl; |
| 51 |
|
|
#endif |
| 52 |
|
|
|
| 53 |
|
|
osin << ac-3; av += 3; |
| 54 |
|
|
while(*av) osin << *av++ << ' '; |
| 55 |
|
|
osin << endl; |
| 56 |
|
|
|
| 57 |
|
|
return 0; |
| 58 |
|
|
} |
| 59 |
|
|
|
| 60 |
|
|
|
| 61 |
|
|
|