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

Side by Side Diff: libraries/nacl-mounts/net/TcpSocket.cc

Issue 10556007: changes in memory mount and socket subsystem to port thttpd (Closed) Base URL: http://naclports.googlecode.com/svn/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « libraries/nacl-mounts/net/TcpSocket.h ('k') | libraries/nacl-mounts/net/newlib_compat.h » ('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 (c) 2012 The Native Client Authors. All rights reserved. 1 // Copyright (c) 2012 The Native Client 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/TcpSocket.h" 5 #include "net/TcpSocket.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <string.h> 8 #include <string.h>
9 #include "../net/SocketSubSystem.h" 9 #include "../net/SocketSubSystem.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/cpp/module.h" 11 #include "ppapi/cpp/module.h"
12 #include "ppapi/cpp/private/net_address_private.h"
12 #include "../util/DebugPrint.h" 13 #include "../util/DebugPrint.h"
13 #include "../util/PthreadHelpers.h" 14 #include "../util/PthreadHelpers.h"
14 15
15 TCPSocket::TCPSocket(SocketSubSystem* sys, int oflag) 16 TCPSocket::TCPSocket(SocketSubSystem* sys, int oflag)
16 : ref_(1), oflag_(oflag), factory_(this), socket_(NULL), 17 : ref_(1), oflag_(oflag), factory_(this), socket_(NULL),
17 read_buf_(kBufSize), write_sent_(false), sys_(sys) { 18 read_buf_(kBufSize), write_sent_(false), sys_(sys) {
18 } 19 }
19 20
20 TCPSocket::~TCPSocket() { 21 TCPSocket::~TCPSocket() {
21 assert(!socket_); 22 assert(!socket_);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 SimpleAutoLock lock(sys_->mutex()); 156 SimpleAutoLock lock(sys_->mutex());
156 assert(!socket_); 157 assert(!socket_);
157 socket_ = new pp::TCPSocketPrivate(sys_->instance()); 158 socket_ = new pp::TCPSocketPrivate(sys_->instance());
158 *pres = socket_->Connect(host, port, 159 *pres = socket_->Connect(host, port,
159 factory_.NewCallback(&TCPSocket::OnConnect, pres)); 160 factory_.NewCallback(&TCPSocket::OnConnect, pres));
160 if (*pres != PP_OK_COMPLETIONPENDING) { 161 if (*pres != PP_OK_COMPLETIONPENDING) {
161 sys_->cond().broadcast(); 162 sys_->cond().broadcast();
162 } 163 }
163 } 164 }
164 165
166 void TCPSocket::GetAddress(struct sockaddr* addr) {
167 struct sockaddr_in* iaddr = (struct sockaddr_in*) addr;
168 struct sockaddr_in6* iaddr6 = (struct sockaddr_in6*) addr;
169 PP_NetAddress_Private netaddr;
170 socket_->GetRemoteAddress(&netaddr);
171 PP_NetAddressFamily_Private family =
172 pp::NetAddressPrivate::GetFamily(netaddr);
173 if (family == PP_NETADDRESSFAMILY_IPV4)
174 iaddr->sin_family = AF_INET;
175 else if (family == PP_NETADDRESSFAMILY_IPV6)
176 iaddr->sin_family = AF_INET6;
177 else {
178 iaddr->sin_family = AF_UNSPEC;
179 return;
180 }
181 iaddr6->sin6_port = pp::NetAddressPrivate::GetPort(netaddr);
182 if (family == PP_NETADDRESSFAMILY_IPV6) {
183 pp::NetAddressPrivate::GetAddress(
184 netaddr, &iaddr6->sin6_addr, sizeof(in6_addr));
185 } else {
186 pp::NetAddressPrivate::GetAddress(
187 netaddr, &iaddr->sin_addr, sizeof(in_addr));
188 }
189 }
190
165 void TCPSocket::OnConnect(int32_t result, int32_t* pres) { 191 void TCPSocket::OnConnect(int32_t result, int32_t* pres) {
166 SimpleAutoLock lock(sys_->mutex()); 192 SimpleAutoLock lock(sys_->mutex());
167 if (result == PP_OK) { 193 if (result == PP_OK) {
168 Read(PP_OK, NULL); 194 Read(PP_OK, NULL);
169 } else { 195 } else {
170 delete socket_; 196 delete socket_;
171 socket_ = NULL; 197 socket_ = NULL;
172 } 198 }
173 *pres = result; 199 *pres = result;
174 sys_->cond().broadcast(); 200 sys_->cond().broadcast();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 bool TCPSocket::Accept(int32_t result, PP_Resource resource, int32_t* pres) { 291 bool TCPSocket::Accept(int32_t result, PP_Resource resource, int32_t* pres) {
266 SimpleAutoLock lock(sys_->mutex()); 292 SimpleAutoLock lock(sys_->mutex());
267 assert(!socket_); 293 assert(!socket_);
268 socket_ = new pp::TCPSocketPrivate(pp::PassRef(), resource); 294 socket_ = new pp::TCPSocketPrivate(pp::PassRef(), resource);
269 Read(PP_OK, NULL); 295 Read(PP_OK, NULL);
270 *pres = PP_OK; 296 *pres = PP_OK;
271 sys_->cond().broadcast(); 297 sys_->cond().broadcast();
272 return true; 298 return true;
273 } 299 }
274 300
OLDNEW
« no previous file with comments | « libraries/nacl-mounts/net/TcpSocket.h ('k') | libraries/nacl-mounts/net/newlib_compat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698