Epoll websocket multiple events for large message size

Viewed 209

I am working on project using GO and we are using websocket protocol for communication between the clients and server. Whenever a client connects we are registering the read descriptor of the connection with an epoll watcher to watch for read events in edge triggered mode. The challenge we are facing is that we are getting multiple events for a single message when the message size is large eg: 1 MB plus. Now, For the first event we are able to read the entire message from the underlying net connection but for subsequent events as there is no data to read it get's blocked on read from underlying socket connection.

Any help on how to identify false positive events from epoll and exit an read from underlying http net.conn is much appreciated.

Code:

// conn is the net connection 
desc, _ := netpoll.HandleRead(conn) // gets the read descriptor 
err = poller.Start(desc, func(ev netpoll.Event) {
    // Callback function when event is received by epoll

    if ev&(netpoll.EventReadHup|netpoll.EventHup) != 0 {
        return
    }
    _, d, _ := wsutil.NextReader(conn, ws.StateServerSide)
    data, _ := ioutil.ReadAll(d)
     // .... handle the data
     // ........
    fmt.Println(string(data))
})
0 Answers
Related