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

Side by Side Diff: net/third_party/udt/app/appserver.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/appclient.cpp ('k') | net/third_party/udt/app/cc.h » ('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* recvdata(void*);
19 #else
20 DWORD WINAPI recvdata(LPVOID);
21 #endif
22
23
24 int main(int argc, char* argv[])
25 {
26 if ((1 != argc) && ((2 != argc) || (0 == atoi(argv[1]))))
27 {
28 cout << "usage: appserver [server_port]" << endl;
29 return 0;
30 }
31
32 // use this function to initialize the UDT library
33 UDT::startup();
34
35 addrinfo hints;
36 addrinfo* res;
37
38 memset(&hints, 0, sizeof(struct addrinfo));
39
40 hints.ai_flags = AI_PASSIVE;
41 hints.ai_family = AF_INET;
42 hints.ai_socktype = SOCK_STREAM;
43 //hints.ai_socktype = SOCK_DGRAM;
44
45 string service("9000");
46 if (2 == argc)
47 service = argv[1];
48
49 if (0 != getaddrinfo(NULL, service.c_str(), &hints, &res))
50 {
51 cout << "illegal port number or port is busy.\n" << endl;
52 return 0;
53 }
54
55 UDTSOCKET serv = UDT::socket(res->ai_family, res->ai_socktype, res->ai_protoc ol);
56
57 // UDT Options
58 //UDT::setsockopt(serv, 0, UDT_CC, new CCCFactory<CUDPBlast>, sizeof(CCCFacto ry<CUDPBlast>));
59 //UDT::setsockopt(serv, 0, UDT_MSS, new int(9000), sizeof(int));
60 //UDT::setsockopt(serv, 0, UDT_RCVBUF, new int(10000000), sizeof(int));
61 //UDT::setsockopt(serv, 0, UDP_RCVBUF, new int(10000000), sizeof(int));
62
63 if (UDT::ERROR == UDT::bind(serv, res->ai_addr, res->ai_addrlen))
64 {
65 cout << "bind: " << UDT::getlasterror().getErrorMessage() << endl;
66 return 0;
67 }
68
69 freeaddrinfo(res);
70
71 cout << "server is ready at port: " << service << endl;
72
73 if (UDT::ERROR == UDT::listen(serv, 10))
74 {
75 cout << "listen: " << UDT::getlasterror().getErrorMessage() << endl;
76 return 0;
77 }
78
79 sockaddr_storage clientaddr;
80 int addrlen = sizeof(clientaddr);
81
82 UDTSOCKET recver;
83
84 while (true)
85 {
86 if (UDT::INVALID_SOCK == (recver = UDT::accept(serv, (sockaddr*)&clientadd r, &addrlen)))
87 {
88 cout << "accept: " << UDT::getlasterror().getErrorMessage() << endl;
89 return 0;
90 }
91
92 char clienthost[NI_MAXHOST];
93 char clientservice[NI_MAXSERV];
94 getnameinfo((sockaddr *)&clientaddr, addrlen, clienthost, sizeof(clienthos t), clientservice, sizeof(clientservice), NI_NUMERICHOST|NI_NUMERICSERV);
95 cout << "new connection: " << clienthost << ":" << clientservice << endl;
96
97 #ifndef WIN32
98 pthread_t rcvthread;
99 pthread_create(&rcvthread, NULL, recvdata, new UDTSOCKET(recver));
100 pthread_detach(rcvthread);
101 #else
102 CreateThread(NULL, 0, recvdata, new UDTSOCKET(recver), 0, NULL);
103 #endif
104 }
105
106 UDT::close(serv);
107
108 // use this function to release the UDT library
109 UDT::cleanup();
110
111 return 1;
112 }
113
114 #ifndef WIN32
115 void* recvdata(void* usocket)
116 #else
117 DWORD WINAPI recvdata(LPVOID usocket)
118 #endif
119 {
120 UDTSOCKET recver = *(UDTSOCKET*)usocket;
121 delete (UDTSOCKET*)usocket;
122
123 char* data;
124 int size = 100000;
125 data = new char[size];
126
127 while (true)
128 {
129 int rsize = 0;
130 int rs;
131 while (rsize < size)
132 {
133 if (UDT::ERROR == (rs = UDT::recv(recver, data + rsize, size - rsize, 0 )))
134 {
135 cout << "recv:" << UDT::getlasterror().getErrorMessage() << endl;
136 break;
137 }
138
139 rsize += rs;
140 }
141
142 if (rsize < size)
143 break;
144 }
145
146 delete [] data;
147
148 UDT::close(recver);
149
150 #ifndef WIN32
151 return NULL;
152 #else
153 return 0;
154 #endif
155 }
OLDNEW
« no previous file with comments | « net/third_party/udt/app/appclient.cpp ('k') | net/third_party/udt/app/cc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698