github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/tcp/socket-status.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package tcp 4 5 import "sync/atomic" 6 7 const ( 8 SocketState_Unset SocketState = iota 9 // represents waiting for a connection request from any remote TCP and port 10 SocketState_LISTEN 11 // represents waiting for a matching connection request after having sent a connection request. 12 SocketState_SYN_SENT 13 // represents waiting for a confirming connection request acknowledgment 14 // after having both received and sent a connection request. 15 SocketState_SYN_RECEIVED 16 /* represents an open connection, data received can be 17 delivered to the user. The normal state for the data transfer phase 18 of the connection. */ 19 SocketState_ESTABLISHED 20 // represents waiting for a connection termination request from the remote TCP, 21 // or an acknowledgment of the connection termination request previously sent. 22 SocketState_FIN_WAIT_1 23 // represents waiting for a connection termination request from the remote TCP. 24 SocketState_FIN_WAIT_2 25 // represents no connection state at all. 26 SocketState_CLOSE 27 // represents waiting for a connection termination request from the local user. 28 SocketState_CLOSE_WAIT 29 // represents waiting for a connection termination request acknowledgment from the remote TCP. 30 SocketState_CLOSING 31 // represents waiting for an acknowledgment of the connection termination request previously sent to the remote TCP 32 // which includes an acknowledgment of its connection termination request 33 SocketState_LAST_ACK 34 // represents waiting for enough time to pass to be sure the remote TCP received the acknowledgment 35 // of its connection termination request. 36 SocketState_TIME_WAIT 37 38 // SocketState_NEW_SYN_RECV 39 ) 40 41 // SocketState use to indicate socket state. 42 type SocketState uint32 43 44 func (s *SocketState) Load() SocketState { 45 return SocketState(atomic.LoadUint32((*uint32)(s))) 46 } 47 func (s *SocketState) Store(SocketState SocketState) { 48 atomic.StoreUint32((*uint32)(s), uint32(SocketState)) 49 } 50 func (s *SocketState) CompareAndSwap(old, new SocketState) (swapped bool) { 51 return atomic.CompareAndSwapUint32((*uint32)(s), uint32(old), uint32(new)) 52 }