@@ -111,14 +111,17 @@ func (c *webRTCConn) RemoteAddr() net.Addr {
}
func (c * webRTCConn ) SetDeadline (t time.Time ) error {
// nolint: golint
return fmt .Errorf ("SetDeadline not implemented" )
}
func (c * webRTCConn ) SetReadDeadline (t time.Time ) error {
// nolint: golint
return fmt .Errorf ("SetReadDeadline not implemented" )
}
func (c * webRTCConn ) SetWriteDeadline (t time.Time ) error {
// nolint: golint
return fmt .Errorf ("SetWriteDeadline not implemented" )
}
@@ -206,12 +209,16 @@ type timeoutConn struct {
}
func (tc timeoutConn ) Read (buf []byte ) (int , error ) {
tc .c .SetDeadline (time .Now ().Add (tc .t ))
if err := tc .c .SetDeadline (time .Now ().Add (tc .t )); err != nil {
log .Printf ("calling SetDeadline in Read returned the following error: %v" , err )
}
return tc .c .Read (buf )
}
func (tc timeoutConn ) Write (buf []byte ) (int , error ) {
tc .c .SetDeadline (time .Now ().Add (tc .t ))
if err := tc .c .SetDeadline (time .Now ().Add (tc .t )); err != nil {
log .Printf ("calling SetDeadline in Write returned the following error: %v" , err )
}
return tc .c .Write (buf )
}
@@ -225,7 +232,9 @@ func CopyLoopTimeout(c1 net.Conn, c2 net.Conn, timeout time.Duration) {
var wg sync.WaitGroup
copyer := func (dst io.ReadWriteCloser , src io.ReadWriteCloser ) {
defer wg .Done ()
io .Copy (dst , src )
if _ , err := io .Copy (dst , src ); err != nil {
log .Printf ("io.Copy inside CopyLoopTimeout generated an error: %v" , err )
}
dst .Close ()
src .Close ()
}
@@ -303,9 +312,12 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
}
dc .OnMessage = func (msg []byte ) {
log .Printf ("OnMessage <--- %d bytes" , len (msg ))
n , err := pw .Write (msg )
var n int
n , err = pw .Write (msg )
if err != nil {
pw .CloseWithError (err )
if inerr := pw .CloseWithError (err ); inerr != nil {
log .Printf ("close with error generated an error: %v" , inerr )
}
}
if n != len (msg ) {
panic ("short write" )
@@ -317,7 +329,9 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
err = pc .SetRemoteDescription (sdp )
if err != nil {
pc .Destroy ()
if inerr := pc .Destroy (); inerr != nil {
log .Printf ("unable to call pc.Destroy after pc.SetRemoteDescription with error: %v" , inerr )
}
return nil , fmt .Errorf ("accept: SetRemoteDescription: %s" , err )
}
log .Println ("sdp offer successfully received." )
@@ -328,18 +342,24 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
// not putting this in a separate go routine, because we need
// SetLocalDescription(answer) to be called before sendAnswer
if err != nil {
pc .Destroy ()
if inerr := pc .Destroy (); inerr != nil {
log .Printf ("ICE gathering has generated an error when calling pc.Destroy: %v" , inerr )
}
return nil , err
}
if answer == nil {
pc .Destroy ()
return nil , fmt .Errorf ("Failed gathering ICE candidates." )
if err = pc .Destroy (); err != nil {
log .Printf ("pc.destroy when gathering ICE candidates returned : %v" , err )
}
return nil , fmt .Errorf ("failed gathering ICE candidates" )
}
err = pc .SetLocalDescription (answer )
if err != nil {
pc .Destroy ()
if err = pc .Destroy (); err != nil {
log .Printf ("pc.destroy after setting local description returned : %v" , err )
}
return nil , err
}
@@ -363,7 +383,9 @@ func runSession(sid string) {
err = sendAnswer (sid , pc )
if err != nil {
log .Printf ("error sending answer to client through broker: %s" , err )
pc .Destroy ()
if inerr := pc .Destroy (); inerr != nil {
log .Printf ("error calling destroy: %v" , inerr )
}
retToken ()
return
}
@@ -375,7 +397,9 @@ func runSession(sid string) {
log .Println ("Connection successful." )
case <- time .After (dataChannelTimeout ):
log .Println ("Timed out waiting for client to open data channel." )
pc .Destroy ()
if err := pc .Destroy (); err != nil {
log .Printf ("error calling Destroy: %v" , err )
}
retToken ()
}
}