2 #include <SocketHandler.h>
3 #include <ListenSocket.h>
6 static bool quit
= false;
9 class IOSocket
: public TcpSocket
12 IOSocket(ISocketHandler
& h
) : TcpSocket(h
) {
18 Utility::GetTime(&m_start
);
19 while (GetOutputLength() < 500000)
21 Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
22 Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
23 Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
24 Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
25 Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
26 Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
27 Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
28 Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
41 void OnWriteComplete() {
42 printf("OnWriteComplete\n");
44 Utility::GetTime(&tv
);
46 tv
.tv_sec
-= m_start
.tv_sec
;
47 tv
.tv_usec
-= m_start
.tv_usec
;
48 Utility::GetTime(&m_start
);
51 tv
.tv_usec
+= 1000000;
54 double t
= tv
.tv_usec
;
57 printf(" Time: %ld.%06ld (%f)\n", tv
.tv_sec
, tv
.tv_usec
, t
);
58 double r
= GetBytesReceived();
59 printf(" bytes in: %lld (%f Mbytes/sec)\n", GetBytesReceived(true), r
/ t
/ 1000000);
60 double s
= GetBytesSent();
61 printf(" bytes out: %lld (%f Mbytes/sec)\n", GetBytesSent(true), s
/ t
/ 1000000);
64 while (GetOutputLength() < 500000)
66 Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
67 Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
68 Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
69 Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
70 Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
71 Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
72 Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
73 Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
78 void OnLine(const std::string
& line
) {
82 Utility::GetTime(&tv
);
84 tv
.tv_sec
-= m_start
.tv_sec
;
85 tv
.tv_usec
-= m_start
.tv_usec
;
86 Utility::GetTime(&m_start
);
89 tv
.tv_usec
+= 1000000;
92 double t
= tv
.tv_usec
;
95 printf(" Time: %ld.%06ld (%f)\n", tv
.tv_sec
, tv
.tv_usec
, t
);
96 double r
= GetBytesReceived();
97 printf(" bytes in: %lld (%f Mbytes/sec)\n", GetBytesReceived(true), r
/ t
/ 1000000);
98 double s
= GetBytesSent();
99 printf(" bytes out: %lld (%f Mbytes/sec)\n", GetBytesSent(true), s
/ t
/ 1000000);
104 if (line
!= "zzzzzzzzzmmmmmmmmm1234lkkk54" &&
105 line
!= "zzzzzzzzzmmmmmmmmm1234lkkk543")
107 printf("\n-------------------------------------------------------\n");
108 for (size_t i
= 0; i
< line
.size(); i
++)
109 if (!isprint(line
[i
]))
110 printf("<%d>", line
[i
]);
112 printf("%c", line
[i
]);
120 struct timeval m_start
;
124 int main(int argc
, char *argv
[])
127 ListenSocket
<IOSocket
> l(h
);
131 sock
.Open("192.168.7.4", 12344);