github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/protocol/networking-stream.go (about) 1 /* For license and copyright information please see the LEGAL file in the code repository */ 2 3 package protocol 4 5 // Stream indicate a minimum networking stream functionality usually occur in layer 4. 6 // It must also implement chunks managing like sRPC, QUIC, TCP, UDP, ... 7 type Stream interface { 8 Connection() Connection 9 Handler() NetworkCommonHandler // usage is like TCP||UDP ports that indicate payload protocol like TLS, HTTPv1, HTTPv2, ... 10 Service() Service // 11 Error() Error // just indicate peer error that receive by response of the request. 12 13 // Authorize request by data in related stream and connection by any data like service, time, ... 14 // Dev must extend this method in each service by it uses. 15 Authorize() (err Error) 16 17 Stream_ID 18 Network_Status 19 Timeout 20 OperationImportance // base on the connection and the service priority and weight 21 StreamOptions 22 StreamLowLevelAPIs 23 } 24 25 // StreamLowLevelAPIs is low level APIs, don't use them in the services layer, if you don't know how it can be effect the application. 26 // It will use in chunks managing packages e.g. sRPC, QUIC, TCP, UDP, ... or Application layer protocols e.g. HTTP, ... 27 type StreamLowLevelAPIs interface { 28 Send(data Codec) (err Error) // Listen to stream state to check request successfully send, response ready to serve, ... 29 Close() (err Error) // Just once, must deregister the stream from the connection and notify peer in some proper way. 30 31 // use to save state and release thread(goroutine) in waiting state 32 Request() any 33 Response() any 34 SetRequest(req any) 35 SetResponse(res any) 36 37 SetHandler(nch NetworkCommonHandler) // Just once, (But some protocol like http allow to change it after first set in a reusable stream like IP/TCP, Allow them??) 38 SetService(ser Service) // Just once, (But some protocol like http allow to change it after first set in a reusable stream like IP/TCP, Allow them??) 39 SetError(err Error) // Just once 40 // Put in related queue to process income stream in non-blocking mode, means It must not block the caller in any ways. 41 // Stream must start with NetworkStatus_NeedMoreData if it doesn't need to call the service when the state changed for the first time 42 ScheduleProcessingStream() 43 44 Codec 45 } 46 47 type StreamOptions interface { 48 // release any underling data reference until call time without need to release socket itself 49 Discard(n int) (discarded int, err Error) 50 SetLinger(d Duration) error 51 SetKeepAlivePeriod(d Duration) error 52 SetNoDelay(noDelay bool) error 53 }