starpc 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpc",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -58,7 +58,7 @@ func (r *ClientRPC) HandlePacketData(data []byte) error {
58
58
  return r.HandlePacket(pkt)
59
59
  }
60
60
 
61
- // HandleStreamClose handles the incoming stream closing w/ optional error.
61
+ // HandleStreamClose handles the stream closing optionally w/ an error.
62
62
  func (r *ClientRPC) HandleStreamClose(closeErr error) {
63
63
  r.mtx.Lock()
64
64
  defer r.mtx.Unlock()
package/srpc/net.go ADDED
@@ -0,0 +1,44 @@
1
+ package srpc
2
+
3
+ import (
4
+ "context"
5
+ "net"
6
+ )
7
+
8
+ // Dial dials a remote server using TCP with the default muxed conn type.
9
+ func Dial(addr string) (Client, error) {
10
+ nconn, err := net.Dial("tcp", addr)
11
+ if err != nil {
12
+ return nil, err
13
+ }
14
+ muxedConn, err := NewMuxedConn(nconn, false, nil)
15
+ if err != nil {
16
+ return nil, err
17
+ }
18
+ return NewClientWithMuxedConn(muxedConn), nil
19
+ }
20
+
21
+ // Listen listens for incoming connections with TCP on the given address with the default muxed conn type.
22
+ // Returns on any fatal error or if ctx was canceled.
23
+ // errCh is an optional error channel (can be nil)
24
+ func Listen(ctx context.Context, addr string, srv *Server, errCh <-chan error) error {
25
+ lis, err := net.Listen("tcp", addr)
26
+ if err != nil {
27
+ return err
28
+ }
29
+
30
+ listenErrCh := make(chan error, 1)
31
+ go func() {
32
+ listenErrCh <- AcceptMuxedListener(ctx, lis, srv, nil)
33
+ _ = lis.Close()
34
+ }()
35
+
36
+ select {
37
+ case <-ctx.Done():
38
+ return context.Canceled
39
+ case err := <-errCh:
40
+ return err
41
+ case err := <-listenErrCh:
42
+ return err
43
+ }
44
+ }