1 // Copyright 2014 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 NET_SOCKET_UNIX_DOMAIN_SERVER_SOCKET_POSIX_H_
6 #define NET_SOCKET_UNIX_DOMAIN_SERVER_SOCKET_POSIX_H_
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "net/base/net_export.h"
17 #include "net/socket/server_socket.h"
18 #include "net/socket/socket_descriptor.h"
24 // Unix Domain Server Socket Implementation. Supports abstract namespaces on
26 class NET_EXPORT UnixDomainServerSocket
: public ServerSocket
{
28 // Callback that returns whether the already connected client, identified by
29 // its process |user_id| and |group_id|, is allowed to keep the connection
30 // open. Note that the socket is closed immediately in case the callback
32 typedef base::Callback
<bool (uid_t user_id
, gid_t group_id
)> AuthCallback
;
34 UnixDomainServerSocket(const AuthCallback
& auth_callack
,
35 bool use_abstract_namespace
);
36 virtual ~UnixDomainServerSocket();
38 // Gets UID and GID of peer to check permissions.
39 static bool GetPeerIds(SocketDescriptor socket_fd
,
43 // ServerSocket implementation.
44 virtual int Listen(const IPEndPoint
& address
, int backlog
) OVERRIDE
;
45 virtual int ListenWithAddressAndPort(const std::string
& unix_domain_path
,
47 int backlog
) OVERRIDE
;
48 virtual int GetLocalAddress(IPEndPoint
* address
) const OVERRIDE
;
49 virtual int Accept(scoped_ptr
<StreamSocket
>* socket
,
50 const CompletionCallback
& callback
) OVERRIDE
;
53 void AcceptCompleted(scoped_ptr
<StreamSocket
>* socket
,
54 const CompletionCallback
& callback
,
56 bool AuthenticateAndGetStreamSocket(scoped_ptr
<StreamSocket
>* socket
);
58 scoped_ptr
<SocketLibevent
> listen_socket_
;
59 const AuthCallback auth_callback_
;
60 const bool use_abstract_namespace_
;
62 scoped_ptr
<SocketLibevent
> accept_socket_
;
64 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocket
);
69 #endif // NET_SOCKET_UNIX_DOMAIN_SOCKET_POSIX_H_