1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "ppapi/cpp/instance.h"
9 #include "ppapi/cpp/tcp_socket.h"
10 #include "ppapi/utility/completion_callback_factory.h"
12 static const int kBufferSize
= 1024;
14 // Simple "echo" server based on a listening pp::TCPSocket.
15 // This server handles just one connection at a time and will
16 // echo back whatever bytes get sent to it.
19 EchoServer(pp::Instance
* instance
, uint16_t port
)
20 : instance_(instance
),
21 callback_factory_(this) {
26 void Start(uint16_t port
);
29 void OnBindCompletion(int32_t result
);
30 void OnListenCompletion(int32_t result
);
31 void OnAcceptCompletion(int32_t result
, pp::TCPSocket socket
);
32 void OnReadCompletion(int32_t result
);
33 void OnWriteCompletion(int32_t result
);
38 pp::Instance
* instance_
;
39 pp::CompletionCallbackFactory
<EchoServer
> callback_factory_
;
40 pp::TCPSocket listening_socket_
;
41 pp::TCPSocket incoming_socket_
;
43 char receive_buffer_
[kBufferSize
];
46 #endif // ECHO_SERVER_H_