blob: 326ab8b5f3b3e3e268f4d01be1210a50da6a97a7 [file] [log] [blame]
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef NET_SOCKET_TCP_SERVER_SOCKET_STARBOARD_H_
#define NET_SOCKET_TCP_SERVER_SOCKET_STARBOARD_H_
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/threading/non_thread_safe.h"
#include "net/base/completion_callback.h"
#include "net/base/net_log.h"
#include "net/socket/server_socket.h"
namespace net {
class IPEndPoint;
class NET_EXPORT_PRIVATE TCPServerSocketStarboard
: public ServerSocket,
public base::NonThreadSafe,
public MessageLoopForIO::Watcher {
public:
TCPServerSocketStarboard(net::NetLog* net_log,
const net::NetLog::Source& source);
virtual ~TCPServerSocketStarboard();
// net::ServerSocket implementation.
virtual void AllowAddressReuse() OVERRIDE;
virtual int Listen(const net::IPEndPoint& address, int backlog) OVERRIDE;
virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
virtual int Accept(scoped_ptr<StreamSocket>* socket,
const CompletionCallback& callback) OVERRIDE;
// MessageLoopForIO::Watcher implementation.
virtual void OnSocketReadyToRead(SbSocket socket) OVERRIDE;
virtual void OnSocketReadyToWrite(SbSocket socket) OVERRIDE;
private:
int SetSocketOptions();
int AcceptInternal(scoped_ptr<StreamSocket>* socket);
void Close();
SbSocket socket_;
MessageLoopForIO::SocketWatcher accept_socket_watcher_;
scoped_ptr<StreamSocket>* accept_socket_;
CompletionCallback accept_callback_;
bool reuse_address_;
BoundNetLog net_log_;
};
} // namespace net
#endif // NET_SOCKET_TCP_SERVER_SOCKET_STARBOARD_H_