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

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
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 int 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 return -1;
Evgeniy Stepanov 2012/06/18 11:23:21 This is not checked at the caller side. Just set t
vissi 2012/06/18 11:29:14 Done.
178 iaddr6->sin6_port = pp::NetAddressPrivate::GetPort(netaddr);
179 if (family == PP_NETADDRESSFAMILY_IPV6) {
180 pp::NetAddressPrivate::GetAddress(
181 netaddr, &iaddr6->sin6_addr, sizeof(in6_addr));
182 } else {
183 pp::NetAddressPrivate::GetAddress(
184 netaddr, &iaddr->sin_addr, sizeof(in_addr));
185 }
186 return 0;
187 }
188
165 void TCPSocket::OnConnect(int32_t result, int32_t* pres) { 189 void TCPSocket::OnConnect(int32_t result, int32_t* pres) {
166 SimpleAutoLock lock(sys_->mutex()); 190 SimpleAutoLock lock(sys_->mutex());
167 if (result == PP_OK) { 191 if (result == PP_OK) {
168 Read(PP_OK, NULL); 192 Read(PP_OK, NULL);
169 } else { 193 } else {
170 delete socket_; 194 delete socket_;
171 socket_ = NULL; 195 socket_ = NULL;
172 } 196 }
173 *pres = result; 197 *pres = result;
174 sys_->cond().broadcast(); 198 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) { 289 bool TCPSocket::Accept(int32_t result, PP_Resource resource, int32_t* pres) {
266 SimpleAutoLock lock(sys_->mutex()); 290 SimpleAutoLock lock(sys_->mutex());
267 assert(!socket_); 291 assert(!socket_);
268 socket_ = new pp::TCPSocketPrivate(pp::PassRef(), resource); 292 socket_ = new pp::TCPSocketPrivate(pp::PassRef(), resource);
269 Read(PP_OK, NULL); 293 Read(PP_OK, NULL);
270 *pres = PP_OK; 294 *pres = PP_OK;
271 sys_->cond().broadcast(); 295 sys_->cond().broadcast();
272 return true; 296 return true;
273 } 297 }
274 298
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698