Send a crash report when a hung process is detected.
[chromium-blink-merge.git] / native_client_sdk / src / examples / api / socket / echo_server.h
blobdb35d7a1eac3a05d94a56f2049e11baa58cd353d
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.
5 #ifndef ECHO_SERVER_H_
6 #define ECHO_SERVER_H_
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.
17 class EchoServer {
18 public:
19 EchoServer(pp::Instance* instance, uint16_t port)
20 : instance_(instance),
21 callback_factory_(this) {
22 Start(port);
25 protected:
26 void Start(uint16_t port);
28 // Callback functions
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);
35 void TryRead();
36 void TryAccept();
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_