Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Side by Side Diff: net/third_party/udt/app/appclient.cpp

Issue 6708091: Remove UDT. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/third_party/udt/app/Makefile ('k') | net/third_party/udt/app/appserver.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #ifndef WIN32
2 #include <unistd.h>
3 #include <cstdlib>
4 #include <cstring>
5 #include <netdb.h>
6 #else
7 #include <winsock2.h>
8 #include <ws2tcpip.h>
9 #include <wspiapi.h>
10 #endif
11 #include <iostream>
12 #include <udt.h>
13 #include "cc.h"
14
15 using namespace std;
16
17 #ifndef WIN32
18 void* monitor(void*);
19 #else
20 DWORD WINAPI monitor(LPVOID);
21 #endif
22
23 int main(int argc, char* argv[])
24 {
25 if ((3 != argc) || (0 == atoi(argv[2])))
26 {
27 cout << "usage: appclient server_ip server_port" << endl;
28 return 0;
29 }
30
31 // use this function to initialize the UDT library
32 UDT::startup();
33
34 struct addrinfo hints, *local, *peer;
35
36 memset(&hints, 0, sizeof(struct addrinfo));
37
38 hints.ai_flags = AI_PASSIVE;
39 hints.ai_family = AF_INET;
40 hints.ai_socktype = SOCK_STREAM;
41 //hints.ai_socktype = SOCK_DGRAM;
42
43 if (0 != getaddrinfo(NULL, "9000", &hints, &local))
44 {
45 cout << "incorrect network address.\n" << endl;
46 return 0;
47 }
48
49 UDTSOCKET client = UDT::socket(local->ai_family, local->ai_socktype, local->a i_protocol);
50
51 // UDT Options
52 //UDT::setsockopt(client, 0, UDT_CC, new CCCFactory<CUDPBlast>, sizeof(CCCFac tory<CUDPBlast>));
53 //UDT::setsockopt(client, 0, UDT_MSS, new int(9000), sizeof(int));
54 //UDT::setsockopt(client, 0, UDT_SNDBUF, new int(10000000), sizeof(int));
55 //UDT::setsockopt(client, 0, UDP_SNDBUF, new int(10000000), sizeof(int));
56
57 // Windows UDP issue
58 // For better performance, modify HKLM\System\CurrentControlSet\Services\Afd\ Parameters\FastSendDatagramThreshold
59 #ifdef WIN32
60 UDT::setsockopt(client, 0, UDT_MSS, new int(1052), sizeof(int));
61 #endif
62
63 // for rendezvous connection, enable the code below
64 /*
65 UDT::setsockopt(client, 0, UDT_RENDEZVOUS, new bool(true), sizeof(bool));
66 if (UDT::ERROR == UDT::bind(client, local->ai_addr, local->ai_addrlen))
67 {
68 cout << "bind: " << UDT::getlasterror().getErrorMessage() << endl;
69 return 0;
70 }
71 */
72
73 freeaddrinfo(local);
74
75 if (0 != getaddrinfo(argv[1], argv[2], &hints, &peer))
76 {
77 cout << "incorrect server/peer address. " << argv[1] << ":" << argv[2] << endl;
78 return 0;
79 }
80
81 // connect to the server, implict bind
82 if (UDT::ERROR == UDT::connect(client, peer->ai_addr, peer->ai_addrlen))
83 {
84 cout << "connect: " << UDT::getlasterror().getErrorMessage() << endl;
85 return 0;
86 }
87
88 freeaddrinfo(peer);
89
90 // using CC method
91 //CUDPBlast* cchandle = NULL;
92 //int temp;
93 //UDT::getsockopt(client, 0, UDT_CC, &cchandle, &temp);
94 //if (NULL != cchandle)
95 // cchandle->setRate(500);
96
97 int size = 100000;
98 char* data = new char[size];
99
100 #ifndef WIN32
101 pthread_create(new pthread_t, NULL, monitor, &client);
102 #else
103 CreateThread(NULL, 0, monitor, &client, 0, NULL);
104 #endif
105
106 for (int i = 0; i < 1000000; i ++)
107 {
108 int ssize = 0;
109 int ss;
110 while (ssize < size)
111 {
112 if (UDT::ERROR == (ss = UDT::send(client, data + ssize, size - ssize, 0 )))
113 {
114 cout << "send:" << UDT::getlasterror().getErrorMessage() << endl;
115 break;
116 }
117
118 ssize += ss;
119 }
120
121 if (ssize < size)
122 break;
123 }
124
125 UDT::close(client);
126
127 delete [] data;
128
129 // use this function to release the UDT library
130 UDT::cleanup();
131
132 return 1;
133 }
134
135 #ifndef WIN32
136 void* monitor(void* s)
137 #else
138 DWORD WINAPI monitor(LPVOID s)
139 #endif
140 {
141 UDTSOCKET u = *(UDTSOCKET*)s;
142
143 UDT::TRACEINFO perf;
144
145 cout << "SendRate(Mb/s)\tRTT(ms)\tCWnd\tPktSndPeriod(us)\tRecvACK\tRecvNAK" < < endl;
146
147 while (true)
148 {
149 #ifndef WIN32
150 sleep(1);
151 #else
152 Sleep(1000);
153 #endif
154
155 if (UDT::ERROR == UDT::perfmon(u, &perf))
156 {
157 cout << "perfmon: " << UDT::getlasterror().getErrorMessage() << endl;
158 break;
159 }
160
161 cout << perf.mbpsSendRate << "\t\t"
162 << perf.msRTT << "\t"
163 << perf.pktCongestionWindow << "\t"
164 << perf.usPktSndPeriod << "\t\t\t"
165 << perf.pktRecvACK << "\t"
166 << perf.pktRecvNAK << endl;
167 }
168
169 #ifndef WIN32
170 return NULL;
171 #else
172 return 0;
173 #endif
174 }
OLDNEW
« no previous file with comments | « net/third_party/udt/app/Makefile ('k') | net/third_party/udt/app/appserver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698