// NewConnection creates a new spdy connection from an existing
// network connection.
func NewConnection(conn net.Conn, server bool) (*Connection, error) {
	framer, framerErr := spdy.NewFramer(conn, conn)
	if framerErr != nil {
		return nil, framerErr
	}
	idleAwareFramer := newIdleAwareFramer(framer)
	var sid spdy.StreamId
	var rid spdy.StreamId
	var pid uint32
	if server {
		sid = 2
		rid = 1
		pid = 2
	} else {
		sid = 1
		rid = 2
		pid = 1
	}

	streamLock := new(sync.RWMutex)
	streamCond := sync.NewCond(streamLock)

	session := &Connection{
		conn:   conn,
		framer: idleAwareFramer,

		closeChan:     make(chan bool),
		goAwayTimeout: time.Duration(0),
		closeTimeout:  time.Duration(0),

		streamLock:       streamLock,
		streamCond:       streamCond,
		streams:          make(map[spdy.StreamId]*Stream),
		nextStreamId:     sid,
		receivedStreamId: rid,

		pingId:    pid,
		pingChans: make(map[uint32]chan error),

		shutdownChan: make(chan error),
	}
	idleAwareFramer.conn = session
	go idleAwareFramer.monitor()

	return session, nil
}
Exemple #2
0
/* Create a new Session object */
func NewSession(conn net.Conn, handler Handler, server bool) (*Session, error) {
	framer, err := spdy.NewFramer(conn, conn)
	if err != nil {
		return nil, err
	}
	return &Session{
		framer,
		server,
		0,
		make(map[uint32]*Stream),
		handler,
		conn,
		0,
		make(map[uint32]*Ping),
		false,
	}, nil
}