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

Side by Side Diff: net/socket/tcp_server_socket_libevent.cc

Issue 10827390: Implement chrome.socket.bind/listen/accept for TCP server socket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 PLOG(ERROR) << "socket() returned an error"; 56 PLOG(ERROR) << "socket() returned an error";
57 return MapSystemError(errno); 57 return MapSystemError(errno);
58 } 58 }
59 59
60 if (SetNonBlocking(socket_)) { 60 if (SetNonBlocking(socket_)) {
61 int result = MapSystemError(errno); 61 int result = MapSystemError(errno);
62 Close(); 62 Close();
63 return result; 63 return result;
64 } 64 }
65 65
66 int optval = 1;
67 setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
68
66 SockaddrStorage storage; 69 SockaddrStorage storage;
67 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) 70 if (!address.ToSockAddr(storage.addr, &storage.addr_len))
68 return ERR_INVALID_ARGUMENT; 71 return ERR_INVALID_ARGUMENT;
69 72
70 int result = bind(socket_, storage.addr, storage.addr_len); 73 int result = bind(socket_, storage.addr, storage.addr_len);
71 if (result < 0) { 74 if (result < 0) {
72 PLOG(ERROR) << "bind() returned an error"; 75 PLOG(ERROR) << "bind() returned an error";
73 result = MapSystemError(errno); 76 result = MapSystemError(errno);
74 Close(); 77 Close();
75 return result; 78 return result;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 accept_callback_.Reset(); 187 accept_callback_.Reset();
185 callback.Run(result); 188 callback.Run(result);
186 } 189 }
187 } 190 }
188 191
189 void TCPServerSocketLibevent::OnFileCanWriteWithoutBlocking(int fd) { 192 void TCPServerSocketLibevent::OnFileCanWriteWithoutBlocking(int fd) {
190 NOTREACHED(); 193 NOTREACHED();
191 } 194 }
192 195
193 } // namespace net 196 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698