diff options
author | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
---|---|---|
committer | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
commit | f154da9e12608589e8d5f0508f908a0c3e88a1bb (patch) | |
tree | f8255d51e10c6f1e0ed69702200b966c9556a431 /src/pkg/runtime/netpoll_kqueue.c | |
parent | 8d8329ed5dfb9622c82a9fbec6fd99a580f9c9f6 (diff) | |
download | golang-upstream/1.4.tar.gz |
Imported Upstream version 1.4upstream/1.4
Diffstat (limited to 'src/pkg/runtime/netpoll_kqueue.c')
-rw-r--r-- | src/pkg/runtime/netpoll_kqueue.c | 111 |
1 files changed, 0 insertions, 111 deletions
diff --git a/src/pkg/runtime/netpoll_kqueue.c b/src/pkg/runtime/netpoll_kqueue.c deleted file mode 100644 index 171346cce..000000000 --- a/src/pkg/runtime/netpoll_kqueue.c +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build darwin dragonfly freebsd netbsd openbsd - -#include "runtime.h" -#include "defs_GOOS_GOARCH.h" -#include "os_GOOS.h" - -// Integrated network poller (kqueue-based implementation). - -int32 runtime·kqueue(void); -int32 runtime·kevent(int32, Kevent*, int32, Kevent*, int32, Timespec*); -void runtime·closeonexec(int32); - -static int32 kq = -1; - -void -runtime·netpollinit(void) -{ - kq = runtime·kqueue(); - if(kq < 0) { - runtime·printf("netpollinit: kqueue failed with %d\n", -kq); - runtime·throw("netpollinit: kqueue failed"); - } - runtime·closeonexec(kq); -} - -int32 -runtime·netpollopen(uintptr fd, PollDesc *pd) -{ - Kevent ev[2]; - int32 n; - - // Arm both EVFILT_READ and EVFILT_WRITE in edge-triggered mode (EV_CLEAR) - // for the whole fd lifetime. The notifications are automatically unregistered - // when fd is closed. - ev[0].ident = (uint32)fd; - ev[0].filter = EVFILT_READ; - ev[0].flags = EV_ADD|EV_CLEAR; - ev[0].fflags = 0; - ev[0].data = 0; - ev[0].udata = (kevent_udata)pd; - ev[1] = ev[0]; - ev[1].filter = EVFILT_WRITE; - n = runtime·kevent(kq, ev, 2, nil, 0, nil); - if(n < 0) - return -n; - return 0; -} - -int32 -runtime·netpollclose(uintptr fd) -{ - // Don't need to unregister because calling close() - // on fd will remove any kevents that reference the descriptor. - USED(fd); - return 0; -} - -void -runtime·netpollarm(PollDesc* pd, int32 mode) -{ - USED(pd, mode); - runtime·throw("unused"); -} - -// Polls for ready network connections. -// Returns list of goroutines that become runnable. -G* -runtime·netpoll(bool block) -{ - static int32 lasterr; - Kevent events[64], *ev; - Timespec ts, *tp; - int32 n, i, mode; - G *gp; - - if(kq == -1) - return nil; - tp = nil; - if(!block) { - ts.tv_sec = 0; - ts.tv_nsec = 0; - tp = &ts; - } - gp = nil; -retry: - n = runtime·kevent(kq, nil, 0, events, nelem(events), tp); - if(n < 0) { - if(n != -EINTR && n != lasterr) { - lasterr = n; - runtime·printf("runtime: kevent on fd %d failed with %d\n", kq, -n); - } - goto retry; - } - for(i = 0; i < n; i++) { - ev = &events[i]; - mode = 0; - if(ev->filter == EVFILT_READ) - mode += 'r'; - if(ev->filter == EVFILT_WRITE) - mode += 'w'; - if(mode) - runtime·netpollready(&gp, (PollDesc*)ev->udata, mode); - } - if(block && gp == nil) - goto retry; - return gp; -} |