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

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

Issue 509133002: Raw SocketDescriptor variant of UnixDomainServerSocket::Accept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix usage of Close(), add a read() to unittest Created 6 years, 3 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
« no previous file with comments | « no previous file | net/socket/socket_libevent.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_SOCKET_SOCKET_LIBEVENT_H_ 5 #ifndef NET_SOCKET_SOCKET_LIBEVENT_H_
6 #define NET_SOCKET_SOCKET_LIBEVENT_H_ 6 #define NET_SOCKET_SOCKET_LIBEVENT_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "net/base/completion_callback.h" 15 #include "net/base/completion_callback.h"
16 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
17 #include "net/socket/socket_descriptor.h" 17 #include "net/socket/socket_descriptor.h"
18 18
19 namespace net { 19 namespace net {
20 20
21 class IOBuffer; 21 class IOBuffer;
22 class IPEndPoint; 22 class IPEndPoint;
23 23
24 // Socket class to provide asynchronous read/write operations on top of the 24 // Socket class to provide asynchronous read/write operations on top of the
25 // posix socket api. It supports AF_INET, AF_INET6, and AF_UNIX addresses. 25 // posix socket api. It supports AF_INET, AF_INET6, and AF_UNIX addresses.
26 class SocketLibevent : public base::MessageLoopForIO::Watcher { 26 class NET_EXPORT_PRIVATE SocketLibevent
27 : public base::MessageLoopForIO::Watcher {
27 public: 28 public:
28 SocketLibevent(); 29 SocketLibevent();
29 virtual ~SocketLibevent(); 30 virtual ~SocketLibevent();
30 31
31 // Opens a socket and returns net::OK if |address_family| is AF_INET, AF_INET6 32 // Opens a socket and returns net::OK if |address_family| is AF_INET, AF_INET6
32 // or AF_UNIX. Otherwise, it does DCHECK() and returns a net error. 33 // or AF_UNIX. Otherwise, it does DCHECK() and returns a net error.
33 int Open(int address_family); 34 int Open(int address_family);
34 // Takes ownership of |socket|. 35 // Takes ownership of |socket|.
35 int AdoptConnectedSocket(SocketDescriptor socket, 36 int AdoptConnectedSocket(SocketDescriptor socket,
36 const SockaddrStorage& peer_address); 37 const SockaddrStorage& peer_address);
38 // Releases ownership of |socket_fd_| to caller.
39 SocketDescriptor ReleaseConnectedSocket();
37 40
38 int Bind(const SockaddrStorage& address); 41 int Bind(const SockaddrStorage& address);
39 42
40 int Listen(int backlog); 43 int Listen(int backlog);
41 int Accept(scoped_ptr<SocketLibevent>* socket, 44 int Accept(scoped_ptr<SocketLibevent>* socket,
42 const CompletionCallback& callback); 45 const CompletionCallback& callback);
43 46
44 // Connects socket. On non-ERR_IO_PENDING error, sets errno and returns a net 47 // Connects socket. On non-ERR_IO_PENDING error, sets errno and returns a net
45 // error code. On ERR_IO_PENDING, |callback| is called with a net error code, 48 // error code. On ERR_IO_PENDING, |callback| is called with a net error code,
46 // not errno, though errno is set if connect event happens with error. 49 // not errno, though errno is set if connect event happens with error.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 89
87 int DoConnect(); 90 int DoConnect();
88 void ConnectCompleted(); 91 void ConnectCompleted();
89 92
90 int DoRead(IOBuffer* buf, int buf_len); 93 int DoRead(IOBuffer* buf, int buf_len);
91 void ReadCompleted(); 94 void ReadCompleted();
92 95
93 int DoWrite(IOBuffer* buf, int buf_len); 96 int DoWrite(IOBuffer* buf, int buf_len);
94 void WriteCompleted(); 97 void WriteCompleted();
95 98
99 void StopWatchingAndCleanUp();
100
96 SocketDescriptor socket_fd_; 101 SocketDescriptor socket_fd_;
97 102
98 base::MessageLoopForIO::FileDescriptorWatcher accept_socket_watcher_; 103 base::MessageLoopForIO::FileDescriptorWatcher accept_socket_watcher_;
99 scoped_ptr<SocketLibevent>* accept_socket_; 104 scoped_ptr<SocketLibevent>* accept_socket_;
100 CompletionCallback accept_callback_; 105 CompletionCallback accept_callback_;
101 106
102 base::MessageLoopForIO::FileDescriptorWatcher read_socket_watcher_; 107 base::MessageLoopForIO::FileDescriptorWatcher read_socket_watcher_;
103 scoped_refptr<IOBuffer> read_buf_; 108 scoped_refptr<IOBuffer> read_buf_;
104 int read_buf_len_; 109 int read_buf_len_;
105 // External callback; called when read is complete. 110 // External callback; called when read is complete.
(...skipping 12 matching lines...) Expand all
118 scoped_ptr<SockaddrStorage> peer_address_; 123 scoped_ptr<SockaddrStorage> peer_address_;
119 124
120 base::ThreadChecker thread_checker_; 125 base::ThreadChecker thread_checker_;
121 126
122 DISALLOW_COPY_AND_ASSIGN(SocketLibevent); 127 DISALLOW_COPY_AND_ASSIGN(SocketLibevent);
123 }; 128 };
124 129
125 } // namespace net 130 } // namespace net
126 131
127 #endif // NET_SOCKET_SOCKET_LIBEVENT_H_ 132 #endif // NET_SOCKET_SOCKET_LIBEVENT_H_
OLDNEW
« no previous file with comments | « no previous file | net/socket/socket_libevent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698