Example #1
0
// NewServerConn is used to create a SPDY connection, using the given
// net.Conn for the underlying connection, and the given http.Server to
// configure the request serving.
func NewServerConn(conn net.Conn, server *http.Server, version, subversion int) (common.Conn, error) {
	if conn == nil {
		return nil, errors.New("Error: Connection initialised with nil net.conn.")
	}
	if server == nil {
		return nil, errors.New("Error: Connection initialised with nil server.")
	}

	switch version {
	case 3:
		return spdy3.NewConn(conn, server, subversion), nil

	case 2:
		return spdy2.NewConn(conn, server), nil

	default:
		return nil, errors.New("Error: Unsupported SPDY version.")
	}
}
Example #2
0
// NewClientConn is used to create a SPDY connection, using the given
// net.Conn for the underlying connection, and the given Receiver to
// receive server pushes.
func NewClientConn(conn net.Conn, push common.Receiver, version, subversion int) (common.Conn, error) {
	if conn == nil {
		return nil, errors.New("Error: Connection initialised with nil net.conn.")
	}

	switch version {
	case 3:
		out := spdy3.NewConn(conn, nil, subversion)
		out.PushReceiver = push
		return out, nil

	case 2:
		out := spdy2.NewConn(conn, nil)
		out.PushReceiver = push
		return out, nil

	default:
		return nil, errors.New("Error: Unrecognised SPDY version.")
	}
}