Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: net/socket/unix_domain_server_socket_posix.h

Issue 348803003: Refactor tcp socket and unix domain socket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments and fixed unittests for chrome os. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef NET_SOCKET_UNIX_DOMAIN_SERVER_SOCKET_POSIX_H_
6 #define NET_SOCKET_UNIX_DOMAIN_SERVER_SOCKET_POSIX_H_
7
8 #include <sys/types.h>
9 #include <string>
mmenke 2014/06/30 18:26:51 nit: Blank line between C headers and C++ headers
byungchul 2014/07/09 22:42:19 Done in https://codereview.chromium.org/376323002/
10
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "net/base/net_export.h"
16 #include "net/socket/server_socket.h"
17 #include "net/socket/socket_descriptor.h"
18
19 namespace net {
20
21 class SocketLibevent;
22
23 // Unix Domain Server Socket Implementation. Supports abstract namespaces on
24 // Linux.
25 class NET_EXPORT UnixDomainServerSocket : public ServerSocket {
26 public:
27 // Callback that returns whether the already connected client, identified by
28 // its process |user_id| and |group_id|, is allowed to keep the connection
29 // open. Note that the socket is closed immediately in case the callback
30 // returns false.
31 typedef base::Callback<bool (uid_t user_id, gid_t group_id)> AuthCallback;
32
33 UnixDomainServerSocket(const AuthCallback& auth_callack,
34 bool use_abstract_namespace);
35 virtual ~UnixDomainServerSocket();
36
37 // Gets UID and GID of peer to check permissions.
38 static bool GetPeerIds(SocketDescriptor socket_fd,
39 uid_t* user_id,
40 gid_t* group_id);
41
42 // ServerSocket implementation.
43 virtual int Listen(const IPEndPoint& address, int backlog) OVERRIDE;
44 virtual int ListenWithAddressAndPort(const std::string& unix_domain_path,
45 int port_unused,
46 int backlog) OVERRIDE;
47 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
48 virtual int Accept(scoped_ptr<StreamSocket>* socket,
49 const CompletionCallback& callback) OVERRIDE;
50
51 private:
52 void AcceptCompleted(scoped_ptr<StreamSocket>* socket,
53 const CompletionCallback& callback,
54 int rv);
55 bool AuthenticateAndGetStreamSocket(scoped_ptr<StreamSocket>* socket);
56
57 scoped_ptr<SocketLibevent> listen_socket_;
58 const AuthCallback auth_callback_;
59 const bool use_abstract_namespace_;
60
61 scoped_ptr<SocketLibevent> accept_socket_;
62
63 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocket);
64 };
65
66 } // namespace net
67
68 #endif // NET_SOCKET_UNIX_DOMAIN_SOCKET_POSIX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698