Skip to content

Band-aid for net.Conn implementations that don't support deadlines.

License

Notifications You must be signed in to change notification settings

adrianosela/deaconn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deaconn

Band-aid for net.Conn implementations that don't support deadlines.

Go Report Card Documentation GitHub issues license

Deaconn stands for "deadline connection".

For usage, see below...

Motivation

Short Version:

If an http.Server's underlying net.Conns do not support deadline methods, WebSockets and any other feature which relies on "hijacking" connections will not work.

Long Version:

This is a small project that was born out of need... I needed to support HTTP traffic over a net.Conn implementation which did not support the SetDeadline, SetReadDeadline, and SetWriteDeadline methods.

This is a problem because the net/http package relies on the deadline methods of net.Conn to support certain features.

Specifically, the net/http package uses SetReadDeadline() to set a connection's deadline to a time in the past in order to abort pending/blocked Read()s on it.

An example where this is done is when type-asserting an http.ResponseWriter as an http.Hijacker and then invoking Hijack() on it (as is done to handle a WebSocket upgrade for instance).

The net.Conn implementation that I specifically was using (which lacked deadlines support) was an (golang.org/x/crypto/ssh).Channel.

More Details:

Usage

To wrap a net.Listener in a listener that adds deadlines support to net.Conns:

wrappedListener := deaconn.NewListenerWithDeadlines(listener)
defer wrappedListener()

// use the wrappedListener as you would use your original listener

To wrap a single net.Conn to add deadline support to it:

wrappedConn := deaconn.NewConnWithDeadlines(conn)

// use the wrappedConn as you would use your original conn

About

Band-aid for net.Conn implementations that don't support deadlines.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages