summaryrefslogtreecommitdiffstats
path: root/net/curvecp/curvecp_server_socket.h
blob: 32be5a430a495d3b83502228afe54c8cde35a728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_CURVECP_CURVECP_SERVER_SOCKET_H_
#define NET_CURVECP_CURVECP_SERVER_SOCKET_H_
#pragma once

#include "net/base/completion_callback.h"
#include "net/curvecp/connection_key.h"
#include "net/curvecp/protocol.h"
#include "net/curvecp/server_messenger.h"
#include "net/curvecp/server_packetizer.h"
#include "net/socket/stream_socket.h"

namespace net {

// A server socket that uses CurveCP as the transport layer.
class CurveCPServerSocket : public Socket,
                            public ServerMessenger::Acceptor {
 public:
  class Acceptor {
   public:
    virtual ~Acceptor() {}
    virtual void OnAccept(CurveCPServerSocket* new_socket) = 0;
  };

  CurveCPServerSocket(net::NetLog* net_log,
                      const net::NetLog::Source& source);
  virtual ~CurveCPServerSocket();

  int Listen(const IPEndPoint& endpoint, Acceptor* acceptor);
  void Close();

  // Socket methods:
  virtual int Read(IOBuffer* buf, int buf_len, OldCompletionCallback* callback);
  virtual int Write(IOBuffer* buf, int buf_len, OldCompletionCallback* callback);
  virtual bool SetReceiveBufferSize(int32 size);
  virtual bool SetSendBufferSize(int32 size);

  // ServerMessenger::Acceptor methods:
  virtual void OnAccept(ConnectionKey key);

 private:
  CurveCPServerSocket(const ConnectionKey& key,
                      ServerPacketizer* packetizer_,
                      net::NetLog* net_log,
                      const net::NetLog::Source& source);
  ServerMessenger* messenger() { return &messenger_; }

  BoundNetLog net_log_;
  scoped_refptr<ServerPacketizer> packetizer_;
  ServerMessenger messenger_;
  Acceptor* acceptor_;
  bool is_child_socket_;  // Was this socket accepted from another.
  ConnectionKey key_;

  DISALLOW_COPY_AND_ASSIGN(CurveCPServerSocket);
};

}  // namespace net

#endif  // NET_CURVECP_CURVECP_SERVER_SOCKET_H_