@@ -7,16 +7,16 @@ package zmq4
77import (
88 "bytes"
99 "encoding/binary"
10+ "errors"
11+ "fmt"
1012 "io"
1113 "net"
1214 "strings"
1315 "sync"
1416 "sync/atomic"
15-
16- "golang.org/x/xerrors"
1717)
1818
19- var ErrClosedConn = xerrors .New ("zmq4: read/write on closed connection" )
19+ var ErrClosedConn = errors .New ("zmq4: read/write on closed connection" )
2020
2121// Conn implements the ZeroMQ Message Transport Protocol as defined
2222// in https://rfc.zeromq.org/spec:23/ZMTP/.
@@ -66,11 +66,11 @@ func (c *Conn) Write(p []byte) (int, error) {
6666// Open performs a complete ZMTP handshake.
6767func Open (rw net.Conn , sec Security , sockType SocketType , sockID SocketIdentity , server bool , onCloseErrorCB func (c * Conn )) (* Conn , error ) {
6868 if rw == nil {
69- return nil , xerrors .Errorf ("zmq4: invalid nil read-writer" )
69+ return nil , fmt .Errorf ("zmq4: invalid nil read-writer" )
7070 }
7171
7272 if sec == nil {
73- return nil , xerrors .Errorf ("zmq4: invalid nil security" )
73+ return nil , fmt .Errorf ("zmq4: invalid nil security" )
7474 }
7575
7676 conn := & Conn {
@@ -89,7 +89,7 @@ func Open(rw net.Conn, sec Security, sockType SocketType, sockID SocketIdentity,
8989
9090 err := conn .init (sec )
9191 if err != nil {
92- return nil , xerrors .Errorf ("zmq4: could not initialize ZMTP connection: %w" , err )
92+ return nil , fmt .Errorf ("zmq4: could not initialize ZMTP connection: %w" , err )
9393 }
9494
9595 return conn , nil
@@ -101,17 +101,17 @@ func (conn *Conn) init(sec Security) error {
101101
102102 err = conn .greet (conn .Server )
103103 if err != nil {
104- return xerrors .Errorf ("zmq4: could not exchange greetings: %w" , err )
104+ return fmt .Errorf ("zmq4: could not exchange greetings: %w" , err )
105105 }
106106
107107 err = conn .sec .Handshake (conn , conn .Server )
108108 if err != nil {
109- return xerrors .Errorf ("zmq4: could not perform security handshake: %w" , err )
109+ return fmt .Errorf ("zmq4: could not perform security handshake: %w" , err )
110110 }
111111
112112 peer := SocketType (conn .Peer .Meta [sysSockType ])
113113 if ! peer .IsCompatible (conn .typ ) {
114- return xerrors .Errorf ("zmq4: peer=%q not compatible with %q" , peer , conn .typ )
114+ return fmt .Errorf ("zmq4: peer=%q not compatible with %q" , peer , conn .typ )
115115 }
116116
117117 // FIXME(sbinet): if security mechanism does not define a client/server
@@ -136,14 +136,14 @@ func (conn *Conn) greet(server bool) error {
136136 err = send .write (conn .rw )
137137 if err != nil {
138138 conn .checkIO (err )
139- return xerrors .Errorf ("zmq4: could not send greeting: %w" , err )
139+ return fmt .Errorf ("zmq4: could not send greeting: %w" , err )
140140 }
141141
142142 var recv greeting
143143 err = recv .read (conn .rw )
144144 if err != nil {
145145 conn .checkIO (err )
146- return xerrors .Errorf ("zmq4: could not recv greeting: %w" , err )
146+ return fmt .Errorf ("zmq4: could not recv greeting: %w" , err )
147147 }
148148
149149 peerKind := asString (recv .Mechanism [:])
@@ -153,7 +153,7 @@ func (conn *Conn) greet(server bool) error {
153153
154154 conn .Peer .Server , err = asBool (recv .Server )
155155 if err != nil {
156- return xerrors .Errorf ("zmq4: could not get peer server flag: %w" , err )
156+ return fmt .Errorf ("zmq4: could not get peer server flag: %w" , err )
157157 }
158158
159159 return nil
@@ -189,7 +189,7 @@ func (c *Conn) SendMsg(msg Msg) error {
189189 }
190190 err := c .send (false , frame , flag )
191191 if err != nil {
192- return xerrors .Errorf ("zmq4: error sending frame %d/%d: %w" , i + 1 , nframes , err )
192+ return fmt .Errorf ("zmq4: error sending frame %d/%d: %w" , i + 1 , nframes , err )
193193 }
194194 }
195195 return nil
@@ -202,7 +202,7 @@ func (c *Conn) RecvMsg() (Msg, error) {
202202 }
203203 msg := c .read ()
204204 if msg .err != nil {
205- return msg , xerrors .Errorf ("zmq4: could not read recv msg: %w" , msg .err )
205+ return msg , fmt .Errorf ("zmq4: could not read recv msg: %w" , msg .err )
206206 }
207207
208208 if ! msg .isCmd () {
@@ -211,19 +211,19 @@ func (c *Conn) RecvMsg() (Msg, error) {
211211
212212 switch len (msg .Frames ) {
213213 case 0 :
214- msg .err = xerrors .Errorf ("zmq4: empty command" )
214+ msg .err = fmt .Errorf ("zmq4: empty command" )
215215 return msg , msg .err
216216 case 1 :
217217 // ok
218218 default :
219- msg .err = xerrors .Errorf ("zmq4: invalid length command" )
219+ msg .err = fmt .Errorf ("zmq4: invalid length command" )
220220 return msg , msg .err
221221 }
222222
223223 var cmd Cmd
224224 msg .err = cmd .unmarshalZMTP (msg .Frames [0 ])
225225 if msg .err != nil {
226- return msg , xerrors .Errorf ("zmq4: could not unmarshal ZMTP recv msg: %w" , msg .err )
226+ return msg , fmt .Errorf ("zmq4: could not unmarshal ZMTP recv msg: %w" , msg .err )
227227 }
228228
229229 switch cmd .Name {
@@ -254,7 +254,7 @@ func (c *Conn) RecvCmd() (Cmd, error) {
254254
255255 msg := c .read ()
256256 if msg .err != nil {
257- return cmd , xerrors .Errorf ("zmq4: could not read recv cmd: %w" , msg .err )
257+ return cmd , fmt .Errorf ("zmq4: could not read recv cmd: %w" , msg .err )
258258 }
259259
260260 if ! msg .isCmd () {
@@ -263,18 +263,18 @@ func (c *Conn) RecvCmd() (Cmd, error) {
263263
264264 switch len (msg .Frames ) {
265265 case 0 :
266- msg .err = xerrors .Errorf ("zmq4: empty command" )
266+ msg .err = fmt .Errorf ("zmq4: empty command" )
267267 return cmd , msg .err
268268 case 1 :
269269 // ok
270270 default :
271- msg .err = xerrors .Errorf ("zmq4: invalid length command" )
271+ msg .err = fmt .Errorf ("zmq4: invalid length command" )
272272 return cmd , msg .err
273273 }
274274
275275 err := cmd .unmarshalZMTP (msg .Frames [0 ])
276276 if err != nil {
277- return cmd , xerrors .Errorf ("zmq4: could not unmarshal ZMTP recv cmd: %w" , err )
277+ return cmd , fmt .Errorf ("zmq4: could not unmarshal ZMTP recv cmd: %w" , err )
278278 }
279279
280280 return cmd , nil
@@ -482,13 +482,13 @@ func (conn *Conn) checkIO(err error) {
482482 return
483483 }
484484
485- if err == io .EOF || xerrors .Is (err , io .EOF ) {
485+ if err == io .EOF || errors .Is (err , io .EOF ) {
486486 conn .SetClosed ()
487487 return
488488 }
489489
490490 var e net.Error
491- if xerrors .As (err , & e ); e != nil && ! e .Timeout () {
491+ if errors .As (err , & e ); e != nil && ! e .Timeout () {
492492 conn .SetClosed ()
493493 }
494494}
0 commit comments