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

Side by Side Diff: runtime/bin/socket_win.cc

Issue 9381003: Set SO_LINGER on sockets on windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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 | « runtime/bin/eventhandler_win.cc ('k') | no next file » | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <winsock2.h> 5 #include <winsock2.h>
6 #include <ws2tcpip.h> 6 #include <ws2tcpip.h>
7 #include <mswsock.h> 7 #include <mswsock.h>
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/eventhandler.h" 10 #include "bin/eventhandler.h"
11 #include "bin/socket.h" 11 #include "bin/socket.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 55
56 56
57 intptr_t Socket::CreateConnect(const char* host, const intptr_t port) { 57 intptr_t Socket::CreateConnect(const char* host, const intptr_t port) {
58 SOCKET s = socket(AF_INET, SOCK_STREAM, 0); 58 SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
59 if (s == INVALID_SOCKET) { 59 if (s == INVALID_SOCKET) {
60 fprintf(stderr, "Error CreateConnect: %d\n", WSAGetLastError()); 60 fprintf(stderr, "Error CreateConnect: %d\n", WSAGetLastError());
61 return -1; 61 return -1;
62 } 62 }
63 63
64 linger l;
65 l.l_onoff = 1;
66 l.l_linger = 10;
67 int status = setsockopt(s,
68 SOL_SOCKET,
69 SO_LINGER,
70 reinterpret_cast<char*>(&l),
71 sizeof(l));
72 if (status != NO_ERROR) {
73 FATAL("Failed setting SO_LINGER on socket");
74 }
75
64 struct hostent* server = gethostbyname(host); 76 struct hostent* server = gethostbyname(host);
65 if (server == NULL) { 77 if (server == NULL) {
66 fprintf(stderr, "Error CreateConnect: %d\n", WSAGetLastError()); 78 fprintf(stderr, "Error CreateConnect: %d\n", WSAGetLastError());
67 closesocket(s); 79 closesocket(s);
68 return -1; 80 return -1;
69 } 81 }
70 82
71 struct sockaddr_in server_address; 83 struct sockaddr_in server_address;
72 server_address.sin_family = AF_INET; 84 server_address.sin_family = AF_INET;
73 server_address.sin_port = htons(port); 85 server_address.sin_port = htons(port);
74 server_address.sin_addr.s_addr = inet_addr(host); 86 server_address.sin_addr.s_addr = inet_addr(host);
75 int status = connect( 87 status = connect(
76 s, 88 s,
77 reinterpret_cast<struct sockaddr *>(&server_address), 89 reinterpret_cast<struct sockaddr *>(&server_address),
78 sizeof(server_address)); 90 sizeof(server_address));
79 if (status == SOCKET_ERROR) { 91 if (status == SOCKET_ERROR) {
80 fprintf(stderr, "Error CreateConnect: %d\n", WSAGetLastError()); 92 fprintf(stderr, "Error CreateConnect: %d\n", WSAGetLastError());
81 closesocket(s); 93 closesocket(s);
82 return -1; 94 return -1;
83 } 95 }
84 96
85 ClientSocket* client_socket = new ClientSocket(s); 97 ClientSocket* client_socket = new ClientSocket(s);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 status = listen(s, backlog); 173 status = listen(s, backlog);
162 if (status == SOCKET_ERROR) { 174 if (status == SOCKET_ERROR) {
163 fprintf(stderr, "Error socket listen: %d\n", WSAGetLastError()); 175 fprintf(stderr, "Error socket listen: %d\n", WSAGetLastError());
164 closesocket(s); 176 closesocket(s);
165 return -1; 177 return -1;
166 } 178 }
167 179
168 ListenSocket* listen_socket = new ListenSocket(s); 180 ListenSocket* listen_socket = new ListenSocket(s);
169 return reinterpret_cast<intptr_t>(listen_socket); 181 return reinterpret_cast<intptr_t>(listen_socket);
170 } 182 }
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698