]>
git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/src/third_party/duktape-1.5.2/examples/eventloop/server-socket-test.js
4 var EXIT_TIMEOUT
= 300e3
;
6 print('automatic exit after ' + (EXIT_TIMEOUT
/ 1e3
) + ' seconds');
7 setTimeout(function () {
9 EventLoop
.requestExit();
12 print('listen on ' + HOST
+ ':' + PORT
);
13 EventLoop
.server(HOST
, PORT
, function (fd
, addr
, port
) {
14 print('new connection on fd ' + fd
+ ' from ' + addr
+ ':' + port
);
15 EventLoop
.setReader(fd
, function (fd
, data
) {
18 // Handle socket data carefully: if you convert it to a string,
19 // it may not be valid UTF-8 etc. Here we operate on the data
20 // directly in the buffer.
22 b
= data
.valueOf(); // ensure we get a plain buffer
24 for (i
= 0; i
< n
; i
++) {
26 if (x
>= 0x61 && x
<= 0x7a) {
27 b
[i
] = x
- 0x20; // uppercase
31 print('read data on fd ' + fd
+ ', length ' + data
.length
);
32 EventLoop
.write(fd
, data
);