OLD | NEW |
1 // Copyright (c) 2012, 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 <arpa/inet.h> | 5 #include <arpa/inet.h> |
6 #include <errno.h> | 6 #include <errno.h> |
7 #include <netdb.h> | 7 #include <netdb.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 if (TEMP_FAILURE_RETRY(listen(fd, backlog)) != 0) { | 183 if (TEMP_FAILURE_RETRY(listen(fd, backlog)) != 0) { |
184 fprintf(stderr, "Error Listen: %s\n", strerror(errno)); | 184 fprintf(stderr, "Error Listen: %s\n", strerror(errno)); |
185 return -1; | 185 return -1; |
186 } | 186 } |
187 | 187 |
188 FDUtils::SetNonBlocking(fd); | 188 FDUtils::SetNonBlocking(fd); |
189 return fd; | 189 return fd; |
190 } | 190 } |
191 | 191 |
| 192 |
192 intptr_t ServerSocket::Accept(intptr_t fd) { | 193 intptr_t ServerSocket::Accept(intptr_t fd) { |
193 intptr_t socket; | 194 intptr_t socket; |
194 struct sockaddr clientaddr; | 195 struct sockaddr clientaddr; |
195 socklen_t addrlen = sizeof(clientaddr); | 196 socklen_t addrlen = sizeof(clientaddr); |
196 socket = TEMP_FAILURE_RETRY(accept(fd, &clientaddr, &addrlen)); | 197 socket = TEMP_FAILURE_RETRY(accept(fd, &clientaddr, &addrlen)); |
197 if (socket < 0) { | 198 if (socket == -1) { |
198 fprintf(stderr, "Error Accept: %s\n", strerror(errno)); | 199 if (errno == EAGAIN) { |
| 200 // We need to signal to the caller that this is actually not an |
| 201 // error. We got woken up from the poll on the listening socket, |
| 202 // but there is no connection ready to be accepted. |
| 203 ASSERT(kTemporaryFailure != -1); |
| 204 socket = kTemporaryFailure; |
| 205 } |
199 } else { | 206 } else { |
200 FDUtils::SetNonBlocking(socket); | 207 FDUtils::SetNonBlocking(socket); |
201 } | 208 } |
202 return socket; | 209 return socket; |
203 } | 210 } |
OLD | NEW |