-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshutdown.go
49 lines (44 loc) · 1.1 KB
/
shutdown.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package tcp
import "errors"
func (conn *TcpConn) VShutdown(sdType int) error {
sock := state.sockets[*conn]
if sdType == SHUTDOWN_BOTH {
if !sock.canRead && !sock.canWrite {
return errors.New("socket read and write already shutdown")
}
if !sock.canRead {
return errors.New("socket read already shutdown")
}
if !sock.canWrite {
return errors.New("socket write already shutdown")
}
sock.canRead = false
sock.canWrite = false
} else if sdType == SHUTDOWN_READ {
if sock.canRead {
sock.canRead = false
} else {
return errors.New("socket read already shutdown")
}
} else if sdType == SHUTDOWN_WRITE {
if sock.canWrite {
sock.canWrite = false
} else {
return errors.New("socket write already shutdown")
}
// signal handlewriter
} else {
return errors.New("invalid shutdown type")
}
if sdType&SHUTDOWN_WRITE != 0 {
sock.writeBufferLock.Lock()
sock.writeBufferIsNotEmpty.Broadcast()
sock.writeBufferLock.Unlock()
}
if sdType&SHUTDOWN_READ != 0 {
sock.readBufferLock.Lock()
sock.readBufferIsNotEmpty.Broadcast()
sock.readBufferLock.Unlock()
}
return nil
}