OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "net/socket/tcp_server_socket_libevent.h" | 5 #include "net/socket/tcp_server_socket_libevent.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <netdb.h> | 9 #include <netdb.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage); | 104 struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage); |
105 if (getsockname(socket_, addr, &addr_len) < 0) | 105 if (getsockname(socket_, addr, &addr_len) < 0) |
106 return MapSystemError(errno); | 106 return MapSystemError(errno); |
107 if (!address->FromSockAddr(addr, addr_len)) | 107 if (!address->FromSockAddr(addr, addr_len)) |
108 return ERR_FAILED; | 108 return ERR_FAILED; |
109 | 109 |
110 return OK; | 110 return OK; |
111 } | 111 } |
112 | 112 |
113 int TCPServerSocketLibevent::Accept( | 113 int TCPServerSocketLibevent::Accept( |
114 scoped_ptr<ClientSocket>* socket, CompletionCallback* callback) { | 114 scoped_ptr<StreamSocket>* socket, CompletionCallback* callback) { |
115 DCHECK(CalledOnValidThread()); | 115 DCHECK(CalledOnValidThread()); |
116 DCHECK(socket); | 116 DCHECK(socket); |
117 DCHECK(callback); | 117 DCHECK(callback); |
118 DCHECK(!accept_callback_); | 118 DCHECK(!accept_callback_); |
119 | 119 |
120 net_log_.BeginEvent(NetLog::TYPE_TCP_ACCEPT, NULL); | 120 net_log_.BeginEvent(NetLog::TYPE_TCP_ACCEPT, NULL); |
121 | 121 |
122 int result = AcceptInternal(socket); | 122 int result = AcceptInternal(socket); |
123 | 123 |
124 if (result == ERR_IO_PENDING) { | 124 if (result == ERR_IO_PENDING) { |
125 if (!MessageLoopForIO::current()->WatchFileDescriptor( | 125 if (!MessageLoopForIO::current()->WatchFileDescriptor( |
126 socket_, true, MessageLoopForIO::WATCH_READ, | 126 socket_, true, MessageLoopForIO::WATCH_READ, |
127 &accept_socket_watcher_, this)) { | 127 &accept_socket_watcher_, this)) { |
128 PLOG(ERROR) << "WatchFileDescriptor failed on read"; | 128 PLOG(ERROR) << "WatchFileDescriptor failed on read"; |
129 return MapSystemError(errno); | 129 return MapSystemError(errno); |
130 } | 130 } |
131 | 131 |
132 accept_socket_ = socket; | 132 accept_socket_ = socket; |
133 accept_callback_ = callback; | 133 accept_callback_ = callback; |
134 } | 134 } |
135 | 135 |
136 return result; | 136 return result; |
137 } | 137 } |
138 | 138 |
139 int TCPServerSocketLibevent::AcceptInternal( | 139 int TCPServerSocketLibevent::AcceptInternal( |
140 scoped_ptr<ClientSocket>* socket) { | 140 scoped_ptr<StreamSocket>* socket) { |
141 struct sockaddr_storage addr_storage; | 141 struct sockaddr_storage addr_storage; |
142 socklen_t addr_len = sizeof(addr_storage); | 142 socklen_t addr_len = sizeof(addr_storage); |
143 struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage); | 143 struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage); |
144 | 144 |
145 int result = HANDLE_EINTR(accept(socket_, addr, &addr_len)); | 145 int result = HANDLE_EINTR(accept(socket_, addr, &addr_len)); |
146 if (result < 0) { | 146 if (result < 0) { |
147 int net_error = MapSystemError(errno); | 147 int net_error = MapSystemError(errno); |
148 if (net_error != ERR_IO_PENDING) | 148 if (net_error != ERR_IO_PENDING) |
149 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error); | 149 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error); |
150 return net_error; | 150 return net_error; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 accept_socket_ = NULL; | 187 accept_socket_ = NULL; |
188 c->Run(result); | 188 c->Run(result); |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 void TCPServerSocketLibevent::OnFileCanWriteWithoutBlocking(int fd) { | 192 void TCPServerSocketLibevent::OnFileCanWriteWithoutBlocking(int fd) { |
193 NOTREACHED(); | 193 NOTREACHED(); |
194 } | 194 } |
195 | 195 |
196 } // namespace net | 196 } // namespace net |
OLD | NEW |