LEFT | RIGHT |
1 // Copyright 2013 The Go Authors. All rights reserved. | 1 // Copyright 2013 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
| 4 |
| 5 // +build linux,386 linux,amd64 |
4 | 6 |
5 #include "runtime.h" | 7 #include "runtime.h" |
6 #include "defs_GOOS_GOARCH.h" | 8 #include "defs_GOOS_GOARCH.h" |
7 | 9 |
8 int32 runtime·epollcreate(int32 size); | 10 int32 runtime·epollcreate(int32 size); |
9 int32 runtime·epollcreate1(int32 flags); | 11 int32 runtime·epollcreate1(int32 flags); |
10 int32 runtime·epollctl(int32 epfd, int32 op, int32 fd, EpollEvent *ev); | 12 int32 runtime·epollctl(int32 epfd, int32 op, int32 fd, EpollEvent *ev); |
11 int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout); | 13 int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout); |
| 14 void runtime·closeonexec(int32 fd); |
12 | 15 |
13 static int32 epfd = -1; // epoll descriptor | 16 static int32 epfd = -1; // epoll descriptor |
14 | 17 |
15 void | 18 void |
16 runtime·netpollinit(void) | 19 runtime·netpollinit(void) |
17 { | 20 { |
18 epfd = runtime·epollcreate1(EPOLL_CLOEXEC); | 21 epfd = runtime·epollcreate1(EPOLL_CLOEXEC); |
19 if(epfd >= 0) | 22 if(epfd >= 0) |
20 return; | 23 return; |
21 epfd = runtime·epollcreate(1024); | 24 epfd = runtime·epollcreate(1024); |
22 if(epfd >= 0) { | 25 if(epfd >= 0) { |
23 » » // TODO(dvyukov): set CLOEXEC | 26 » » runtime·closeonexec(epfd); |
24 return; | 27 return; |
25 } | 28 } |
26 runtime·printf("netpollinit: failed to create descriptor (%d)\n", -epfd)
; | 29 runtime·printf("netpollinit: failed to create descriptor (%d)\n", -epfd)
; |
27 runtime·throw("netpollinit: failed to create descriptor"); | 30 runtime·throw("netpollinit: failed to create descriptor"); |
28 } | 31 } |
29 | 32 |
30 int32 | 33 int32 |
31 runtime·netpollopen(int32 fd, PollDesc *pd) | 34 runtime·netpollopen(int32 fd, PollDesc *pd) |
32 { | 35 { |
33 EpollEvent ev; | 36 EpollEvent ev; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 mode += 'r'; | 71 mode += 'r'; |
69 if(ev->events & (EPOLLOUT|EPOLLHUP|EPOLLERR)) | 72 if(ev->events & (EPOLLOUT|EPOLLHUP|EPOLLERR)) |
70 mode += 'w'; | 73 mode += 'w'; |
71 if(mode) | 74 if(mode) |
72 runtime·netpollready(&gp, (void*)ev->data, mode); | 75 runtime·netpollready(&gp, (void*)ev->data, mode); |
73 } | 76 } |
74 if(block && gp == nil) | 77 if(block && gp == nil) |
75 goto retry; | 78 goto retry; |
76 return gp; | 79 return gp; |
77 } | 80 } |
LEFT | RIGHT |