Hello all,

I'm learning golang and I wanted to try out this. Wanted to make a event
driven server using Kqueue sys call (I'm on mac). A simple echo server will
do. I started with the below code:

func main() {
var lis net.Listener
lis, err = net.Listen("tcp", "localhost:5000")

if err != nil {

p , err := syscall.Kqueue()
[]syscall.Kevent_t{{Ident: uint64(fd),
Flags: syscall.EV_ADD, Filter: syscall.EVFILT_READ}},
nil, nil)


Then later realized that, for attaching the READ for Kqueue, we need a file
descriptor. I'm not sure on how to get the file descriptor from net package
(may be net package does implements the same logic under the hood by
calling out right syscalls for making event driven, but I wanted to try

Also, I wanted to know how to achieve the following:
1. Once I get my file descriptor, I wait for the events on the same using
the appropriate sys calls for kqueue. Lets say a tcp client logs in, sends
a request, I receive the event on my kqueue, now the thing I'm confused is
that, how will I attach my kqueue logic to the opened tcp connection. From
my understanding, usually sockes read/write using read/write syscalls,
which are blocking call. Now using kqueue, we are making it more of event
driven right? So how would I connect my kqueue with the socket to make it
event driven? Any examples would be really great!

Thanks for your help.

You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to