vendor/github.com/gorilla/websocket/conn.go
changeset 256 6d9efbef00a9
parent 251 1c52a0eeb952
child 260 445e01aede7e
equal deleted inserted replaced
255:4f153a23adab 256:6d9efbef00a9
   242 	conn        net.Conn
   242 	conn        net.Conn
   243 	isServer    bool
   243 	isServer    bool
   244 	subprotocol string
   244 	subprotocol string
   245 
   245 
   246 	// Write fields
   246 	// Write fields
   247 	mu            chan bool // used as mutex to protect write to conn
   247 	mu            chan struct{} // used as mutex to protect write to conn
   248 	writeBuf      []byte    // frame is constructed in this buffer.
   248 	writeBuf      []byte        // frame is constructed in this buffer.
   249 	writePool     BufferPool
   249 	writePool     BufferPool
   250 	writeBufSize  int
   250 	writeBufSize  int
   251 	writeDeadline time.Time
   251 	writeDeadline time.Time
   252 	writer        io.WriteCloser // the current writer returned to the application
   252 	writer        io.WriteCloser // the current writer returned to the application
   253 	isWriting     bool           // for best-effort concurrent write detection
   253 	isWriting     bool           // for best-effort concurrent write detection
   300 
   300 
   301 	if writeBuf == nil && writeBufferPool == nil {
   301 	if writeBuf == nil && writeBufferPool == nil {
   302 		writeBuf = make([]byte, writeBufferSize)
   302 		writeBuf = make([]byte, writeBufferSize)
   303 	}
   303 	}
   304 
   304 
   305 	mu := make(chan bool, 1)
   305 	mu := make(chan struct{}, 1)
   306 	mu <- true
   306 	mu <- struct{}{}
   307 	c := &Conn{
   307 	c := &Conn{
   308 		isServer:               isServer,
   308 		isServer:               isServer,
   309 		br:                     br,
   309 		br:                     br,
   310 		conn:                   conn,
   310 		conn:                   conn,
   311 		mu:                     mu,
   311 		mu:                     mu,
   375 	return p, err
   375 	return p, err
   376 }
   376 }
   377 
   377 
   378 func (c *Conn) write(frameType int, deadline time.Time, buf0, buf1 []byte) error {
   378 func (c *Conn) write(frameType int, deadline time.Time, buf0, buf1 []byte) error {
   379 	<-c.mu
   379 	<-c.mu
   380 	defer func() { c.mu <- true }()
   380 	defer func() { c.mu <- struct{}{} }()
   381 
   381 
   382 	c.writeErrMu.Lock()
   382 	c.writeErrMu.Lock()
   383 	err := c.writeErr
   383 	err := c.writeErr
   384 	c.writeErrMu.Unlock()
   384 	c.writeErrMu.Unlock()
   385 	if err != nil {
   385 	if err != nil {
   427 		buf = append(buf, key[:]...)
   427 		buf = append(buf, key[:]...)
   428 		buf = append(buf, data...)
   428 		buf = append(buf, data...)
   429 		maskBytes(key, 0, buf[6:])
   429 		maskBytes(key, 0, buf[6:])
   430 	}
   430 	}
   431 
   431 
   432 	d := time.Hour * 1000
   432 	d := 1000 * time.Hour
   433 	if !deadline.IsZero() {
   433 	if !deadline.IsZero() {
   434 		d = deadline.Sub(time.Now())
   434 		d = deadline.Sub(time.Now())
   435 		if d < 0 {
   435 		if d < 0 {
   436 			return errWriteTimeout
   436 			return errWriteTimeout
   437 		}
   437 		}
   442 	case <-c.mu:
   442 	case <-c.mu:
   443 		timer.Stop()
   443 		timer.Stop()
   444 	case <-timer.C:
   444 	case <-timer.C:
   445 		return errWriteTimeout
   445 		return errWriteTimeout
   446 	}
   446 	}
   447 	defer func() { c.mu <- true }()
   447 	defer func() { c.mu <- struct{}{} }()
   448 
   448 
   449 	c.writeErrMu.Lock()
   449 	c.writeErrMu.Lock()
   450 	err := c.writeErr
   450 	err := c.writeErr
   451 	c.writeErrMu.Unlock()
   451 	c.writeErrMu.Unlock()
   452 	if err != nil {
   452 	if err != nil {