[PD1] Error handling project-wide
This commit is contained in:
parent
f5b3726673
commit
b918211736
13 changed files with 364 additions and 245 deletions
|
@ -22,33 +22,27 @@ func NewConnection[T any](netConn *tls.Conn) Connection[T] {
|
|||
}
|
||||
}
|
||||
|
||||
func (c Connection[T]) Send(obj T) bool {
|
||||
func (c Connection[T]) Send(obj T) error {
|
||||
if err := c.encoder.Encode(&obj); err!=nil {
|
||||
if err == io.EOF {
|
||||
log.Println("Connection closed by peer")
|
||||
//Return false as connection not active
|
||||
return false
|
||||
} else {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
//Return true as connection active
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Connection[T]) Receive() (*T, bool) {
|
||||
func (c Connection[T]) Receive() (*T, error) {
|
||||
var obj T
|
||||
if err := c.decoder.Decode(&obj); err != nil {
|
||||
if err == io.EOF {
|
||||
log.Println("Connection closed by peer")
|
||||
//Return false as connection not active
|
||||
return nil,false
|
||||
} else {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil,err
|
||||
}
|
||||
//Return true as connection active
|
||||
return &obj, true
|
||||
return &obj, nil
|
||||
}
|
||||
|
||||
func (c Connection[T]) GetPeerCertificate() *x509.Certificate {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue