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

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

Issue 296053012: Replace StreamListenSocket with StreamSocket in HttpServer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't export HttpServer which is built in a static lib 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 <string>
9
10 #include "base/basictypes.h"
11 #include "net/base/net_export.h"
12 #include "net/socket/server_socket.h"
13 #include "net/socket/socket_descriptor.h"
14
15 namespace net {
16
17 // Unix Domain Server Socket Implementation. Supports abstract namespaces on
18 // Linux.
19 class NET_EXPORT UnixDomainServerSocket
20 : public ServerSocket,
21 public base::MessageLoopForIO::Watcher {
22 public:
23 // Callback that returns whether the already connected client, identified by
24 // its process |user_id| and |group_id|, is allowed to keep the connection
25 // open. Note that the socket is closed immediately in case the callback
26 // returns false.
27 typedef base::Callback<bool (uid_t user_id, gid_t group_id)> AuthCallback;
28
29 UnixDomainServerSocket(const AuthCallback& auth_callack,
30 bool use_abstract_namespace);
31 virtual ~UnixDomainServerSocket();
32
33 // ServerSocket implementation.
34 virtual int Listen(const IPEndPoint& address, int backlog) OVERRIDE;
35 virtual int ListenWithAddressAndPort(const std::string& unix_domain_path,
36 int port_unused,
37 int backlog) OVERRIDE;
38 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
39 virtual int Accept(scoped_ptr<StreamSocket>* socket,
40 const CompletionCallback& callback) OVERRIDE;
41
42 // base::MessageLoopForIO::Watcher methods.
43 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
44 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
45
46 // Creates a socket and bind to |socket_path|.
47 // Only for android or for linux, |use_abstract_namespace| can be true.
48 // Otherwise, returns ERR_ADDRESS_INVALID.
49 static int CreateAndBind(const std::string& socket_path,
50 bool use_abstract_namespace,
51 SocketDescriptor* socket_fd);
52 // Gets UID and GID of peer to check permissions.
53 static bool GetPeerIds(SocketDescriptor socket_fd,
54 uid_t* user_id,
55 gid_t* group_id);
56 private:
57 void Close();
58 int DoAccept(scoped_ptr<StreamSocket>* socket);
59 void DidCompleteAccept();
60
61 SocketDescriptor socket_fd_;
62 const AuthCallback auth_callback_;
63 const bool use_abstract_namespace_;
64
65 base::MessageLoopForIO::FileDescriptorWatcher accept_socket_watcher_;
66 scoped_ptr<StreamSocket>* accept_socket_;
67 CompletionCallback accept_callback_;
68
69 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocket);
70 };
71
72 } // namespace net
73
74 #endif // NET_SOCKET_UNIX_DOMAIN_SOCKET_POSIX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698