-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathzmq3.go
816 lines (717 loc) · 17.5 KB
/
zmq3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
package zmq3
/*
#cgo !windows pkg-config: libzmq
#cgo windows CFLAGS: -I/usr/local/include
#cgo windows LDFLAGS: -L/usr/local/lib -lzmq
#include <zmq.h>
#include <stdlib.h>
#include <string.h>
#include "zmq3.h"
int
zmq3_major = ZMQ_VERSION_MAJOR,
zmq3_minor = ZMQ_VERSION_MINOR,
zmq3_patch = ZMQ_VERSION_PATCH;
char *get_event(zmq_msg_t *msg, int *ev, int *val) {
zmq_event_t event;
char *s;
int n;
memcpy(&event, zmq_msg_data(msg), sizeof(event));
*ev = event.event;
*val = event.data.connected.fd;
n = strlen(event.data.connected.addr);
s = (char *) malloc(n + 1);
if (s != NULL) {
memcpy(s, event.data.connected.addr, n);
s[n] = '\0';
}
return s;
}
void *my_memcpy(void *dest, const void *src, size_t n) {
return memcpy(dest, src, n);
}
*/
import "C"
import (
"errors"
"fmt"
"runtime"
"strings"
"unsafe"
)
var (
defaultCtx *Context
major, minor, patch int
ErrorContextClosed = errors.New("Context is closed")
ErrorSocketClosed = errors.New("Socket is closed")
ErrorNoEvent = errors.New("Not an event")
ErrorNoSocket = errors.New("No such socket")
initVersionError error
initContextError error
)
func init() {
major, minor, patch = Version()
if major != 3 {
initVersionError = fmt.Errorf("Using zmq3 with ZeroMQ major version %d", major)
return
}
if major != int(C.zmq3_major) || minor != int(C.zmq3_minor) || patch != int(C.zmq3_patch) {
initVersionError =
fmt.Errorf(
"zmq3 was compiled with ZeroMQ version %d.%d.%d, but the runtime links with version %d.%d.%d",
int(C.zmq3_major), int(C.zmq3_minor), int(C.zmq3_patch),
major, minor, patch)
return
}
var err error
defaultCtx = &Context{}
defaultCtx.ctx, err = C.zmq_ctx_new()
if defaultCtx.ctx == nil {
initContextError = fmt.Errorf("Init of ZeroMQ context failed: %v", errget(err))
return
}
defaultCtx.opened = true
}
//. Util
// Report 0MQ library version.
func Version() (major, minor, patch int) {
if initVersionError != nil {
return 0, 0, 0
}
var maj, min, pat C.int
C.zmq_version(&maj, &min, &pat)
return int(maj), int(min), int(pat)
}
// Get 0MQ error message string.
func Error(e int) string {
return C.GoString(C.zmq_strerror(C.int(e)))
}
//. Context
/*
A context that is not the default context.
*/
type Context struct {
ctx unsafe.Pointer
opened bool
err error
}
// Create a new context.
func NewContext() (ctx *Context, err error) {
if initVersionError != nil {
return nil, initVersionError
}
ctx = &Context{}
c, e := C.zmq_ctx_new()
if c == nil {
err = errget(e)
ctx.err = err
} else {
ctx.ctx = c
ctx.opened = true
runtime.SetFinalizer(ctx, (*Context).Term)
}
return
}
/*
Terminates the default context.
For linger behavior, see: http://api.zeromq.org/3-2:zmq-ctx-destroy
*/
func Term() error {
if initVersionError != nil {
return initVersionError
}
if initContextError != nil {
return initContextError
}
return defaultCtx.Term()
}
/*
Terminates the context.
For linger behavior, see: http://api.zeromq.org/3-2:zmq-ctx-destroy
*/
func (ctx *Context) Term() error {
if ctx.opened {
ctx.opened = false
n, err := C.zmq_ctx_destroy(ctx.ctx)
if n != 0 {
ctx.err = errget(err)
}
}
return ctx.err
}
func getOption(ctx *Context, o C.int) (int, error) {
if !ctx.opened {
return 0, ErrorContextClosed
}
nc, err := C.zmq_ctx_get(ctx.ctx, o)
n := int(nc)
if n < 0 {
return n, errget(err)
}
return n, nil
}
// Returns the size of the 0MQ thread pool in the default context.
func GetIoThreads() (int, error) {
if initVersionError != nil {
return 0, initVersionError
}
if initContextError != nil {
return 0, initContextError
}
return defaultCtx.GetIoThreads()
}
// Returns the size of the 0MQ thread pool.
func (ctx *Context) GetIoThreads() (int, error) {
return getOption(ctx, C.ZMQ_IO_THREADS)
}
// Returns the maximum number of sockets allowed in the default context.
func GetMaxSockets() (int, error) {
if initVersionError != nil {
return 0, initVersionError
}
if initContextError != nil {
return 0, initContextError
}
return defaultCtx.GetMaxSockets()
}
// Returns the maximum number of sockets allowed.
func (ctx *Context) GetMaxSockets() (int, error) {
return getOption(ctx, C.ZMQ_MAX_SOCKETS)
}
func setOption(ctx *Context, o C.int, n int) error {
if !ctx.opened {
return ErrorContextClosed
}
i, err := C.zmq_ctx_set(ctx.ctx, o, C.int(n))
if int(i) != 0 {
return errget(err)
}
return nil
}
/*
Specifies the size of the 0MQ thread pool to handle I/O operations in
the default context. If your application is using only the inproc
transport for messaging you may set this to zero, otherwise set it to at
least one. This option only applies before creating any sockets.
Default value: 1
*/
func SetIoThreads(n int) error {
if initVersionError != nil {
return initVersionError
}
if initContextError != nil {
return initContextError
}
return defaultCtx.SetIoThreads(n)
}
/*
Specifies the size of the 0MQ thread pool to handle I/O operations. If
your application is using only the inproc transport for messaging you
may set this to zero, otherwise set it to at least one. This option only
applies before creating any sockets.
Default value: 1
*/
func (ctx *Context) SetIoThreads(n int) error {
return setOption(ctx, C.ZMQ_IO_THREADS, n)
}
/*
Sets the maximum number of sockets allowed in the default context.
Default value: 1024
*/
func SetMaxSockets(n int) error {
if initVersionError != nil {
return initVersionError
}
if initContextError != nil {
return initContextError
}
return defaultCtx.SetMaxSockets(n)
}
/*
Sets the maximum number of sockets allowed.
Default value: 1024
*/
func (ctx *Context) SetMaxSockets(n int) error {
return setOption(ctx, C.ZMQ_MAX_SOCKETS, n)
}
//. Sockets
// Specifies the type of a socket, used by NewSocket()
type Type int
const (
// Constants for NewSocket()
// See: http://api.zeromq.org/3-2:zmq-socket#toc3
REQ = Type(C.ZMQ_REQ)
REP = Type(C.ZMQ_REP)
DEALER = Type(C.ZMQ_DEALER)
ROUTER = Type(C.ZMQ_ROUTER)
PUB = Type(C.ZMQ_PUB)
SUB = Type(C.ZMQ_SUB)
XPUB = Type(C.ZMQ_XPUB)
XSUB = Type(C.ZMQ_XSUB)
PUSH = Type(C.ZMQ_PUSH)
PULL = Type(C.ZMQ_PULL)
PAIR = Type(C.ZMQ_PAIR)
)
/*
Socket type as string.
*/
func (t Type) String() string {
switch t {
case REQ:
return "REQ"
case REP:
return "REP"
case DEALER:
return "DEALER"
case ROUTER:
return "ROUTER"
case PUB:
return "PUB"
case SUB:
return "SUB"
case XPUB:
return "XPUB"
case XSUB:
return "XSUB"
case PUSH:
return "PUSH"
case PULL:
return "PULL"
case PAIR:
return "PAIR"
}
return "<INVALID>"
}
// Used by (*Socket)Send() and (*Socket)Recv()
type Flag int
const (
// Flags for (*Socket)Send(), (*Socket)Recv()
// For Send, see: http://api.zeromq.org/3-2:zmq-send#toc2
// For Recv, see: http://api.zeromq.org/3-2:zmq-msg-recv#toc2
DONTWAIT = Flag(C.ZMQ_DONTWAIT)
SNDMORE = Flag(C.ZMQ_SNDMORE)
)
/*
Socket flag as string.
*/
func (f Flag) String() string {
ff := make([]string, 0)
if f&DONTWAIT != 0 {
ff = append(ff, "DONTWAIT")
}
if f&SNDMORE != 0 {
ff = append(ff, "SNDMORE")
}
if len(ff) == 0 {
return "<NONE>"
}
return strings.Join(ff, "|")
}
// Used by (*Socket)Monitor() and (*Socket)RecvEvent()
type Event int
const (
// Flags for (*Socket)Monitor() and (*Socket)RecvEvent()
// See: http://api.zeromq.org/3-2:zmq-socket-monitor#toc2
EVENT_ALL = Event(C.ZMQ_EVENT_ALL)
EVENT_CONNECTED = Event(C.ZMQ_EVENT_CONNECTED)
EVENT_CONNECT_DELAYED = Event(C.ZMQ_EVENT_CONNECT_DELAYED)
EVENT_CONNECT_RETRIED = Event(C.ZMQ_EVENT_CONNECT_RETRIED)
EVENT_LISTENING = Event(C.ZMQ_EVENT_LISTENING)
EVENT_BIND_FAILED = Event(C.ZMQ_EVENT_BIND_FAILED)
EVENT_ACCEPTED = Event(C.ZMQ_EVENT_ACCEPTED)
EVENT_ACCEPT_FAILED = Event(C.ZMQ_EVENT_ACCEPT_FAILED)
EVENT_CLOSED = Event(C.ZMQ_EVENT_CLOSED)
EVENT_CLOSE_FAILED = Event(C.ZMQ_EVENT_CLOSE_FAILED)
EVENT_DISCONNECTED = Event(C.ZMQ_EVENT_DISCONNECTED)
)
/*
Socket event as string.
*/
func (e Event) String() string {
if e == EVENT_ALL {
return "EVENT_ALL"
}
ee := make([]string, 0)
if e&EVENT_CONNECTED != 0 {
ee = append(ee, "EVENT_CONNECTED")
}
if e&EVENT_CONNECT_DELAYED != 0 {
ee = append(ee, "EVENT_CONNECT_DELAYED")
}
if e&EVENT_CONNECT_RETRIED != 0 {
ee = append(ee, "EVENT_CONNECT_RETRIED")
}
if e&EVENT_LISTENING != 0 {
ee = append(ee, "EVENT_LISTENING")
}
if e&EVENT_BIND_FAILED != 0 {
ee = append(ee, "EVENT_BIND_FAILED")
}
if e&EVENT_ACCEPTED != 0 {
ee = append(ee, "EVENT_ACCEPTED")
}
if e&EVENT_ACCEPT_FAILED != 0 {
ee = append(ee, "EVENT_ACCEPT_FAILED")
}
if e&EVENT_CLOSED != 0 {
ee = append(ee, "EVENT_CLOSED")
}
if e&EVENT_CLOSE_FAILED != 0 {
ee = append(ee, "EVENT_CLOSE_FAILED")
}
if e&EVENT_DISCONNECTED != 0 {
ee = append(ee, "EVENT_DISCONNECTED")
}
if len(ee) == 0 {
return "<NONE>"
}
return strings.Join(ee, "|")
}
// Used by (soc *Socket)GetEvents()
type State int
const (
// Flags for (*Socket)GetEvents()
// See: http://api.zeromq.org/3-2:zmq-getsockopt#toc24
POLLIN = State(C.ZMQ_POLLIN)
POLLOUT = State(C.ZMQ_POLLOUT)
)
/*
Socket state as string.
*/
func (s State) String() string {
ss := make([]string, 0)
if s&POLLIN != 0 {
ss = append(ss, "POLLIN")
}
if s&POLLOUT != 0 {
ss = append(ss, "POLLOUT")
}
if len(ss) == 0 {
return "<NONE>"
}
return strings.Join(ss, "|")
}
/*
Socket functions starting with `Set` or `Get` are used for setting and
getting socket options.
*/
type Socket struct {
soc unsafe.Pointer
ctx *Context
opened bool
err error
}
/*
Socket as string.
*/
func (soc Socket) String() string {
if !soc.opened {
return "Socket(CLOSED)"
}
t, err := soc.GetType()
if err != nil {
return fmt.Sprintf("Socket(%v)", err)
}
i, err := soc.GetIdentity()
if err == nil && i != "" {
return fmt.Sprintf("Socket(%v,%q)", t, i)
}
return fmt.Sprintf("Socket(%v,%p)", t, soc.soc)
}
/*
Create 0MQ socket in the default context.
WARNING:
The Socket is not thread safe. This means that you cannot access the same Socket
from different goroutines without using something like a mutex.
For a description of socket types, see: http://api.zeromq.org/3-2:zmq-socket#toc3
*/
func NewSocket(t Type) (soc *Socket, err error) {
if initVersionError != nil {
return nil, initVersionError
}
if initContextError != nil {
return nil, initContextError
}
return defaultCtx.NewSocket(t)
}
/*
Create 0MQ socket in the given context.
WARNING:
The Socket is not thread safe. This means that you cannot access the same Socket
from different goroutines without using something like a mutex.
For a description of socket types, see: http://api.zeromq.org/3-2:zmq-socket#toc3
*/
func (ctx *Context) NewSocket(t Type) (soc *Socket, err error) {
soc = &Socket{}
if !ctx.opened {
return soc, ErrorContextClosed
}
s, e := C.zmq_socket(ctx.ctx, C.int(t))
if s == nil {
err = errget(e)
soc.err = err
} else {
soc.soc = s
soc.ctx = ctx
soc.opened = true
runtime.SetFinalizer(soc, (*Socket).Close)
}
return
}
// If not called explicitly, the socket will be closed on garbage collection
func (soc *Socket) Close() error {
if soc.opened {
soc.opened = false
if i, err := C.zmq_close(soc.soc); int(i) != 0 {
soc.err = errget(err)
}
soc.soc = unsafe.Pointer(nil)
soc.ctx = nil
}
return soc.err
}
// Return the context associated with a socket
func (soc *Socket) Context() (*Context, error) {
if !soc.opened {
return nil, ErrorSocketClosed
}
return soc.ctx, nil
}
/*
Accept incoming connections on a socket.
For a description of endpoint, see: http://api.zeromq.org/3-2:zmq-bind#toc2
*/
func (soc *Socket) Bind(endpoint string) error {
if !soc.opened {
return ErrorSocketClosed
}
s := C.CString(endpoint)
defer C.free(unsafe.Pointer(s))
if i, err := C.zmq_bind(soc.soc, s); int(i) != 0 {
return errget(err)
}
return nil
}
/*
Stop accepting connections on a socket.
For a description of endpoint, see: http://api.zeromq.org/3-2:zmq-bind#toc2
*/
func (soc *Socket) Unbind(endpoint string) error {
if !soc.opened {
return ErrorSocketClosed
}
s := C.CString(endpoint)
defer C.free(unsafe.Pointer(s))
if i, err := C.zmq_unbind(soc.soc, s); int(i) != 0 {
return errget(err)
}
return nil
}
/*
Create outgoing connection from socket.
For a description of endpoint, see: http://api.zeromq.org/3-2:zmq-connect#toc2
*/
func (soc *Socket) Connect(endpoint string) error {
if !soc.opened {
return ErrorSocketClosed
}
s := C.CString(endpoint)
defer C.free(unsafe.Pointer(s))
if i, err := C.zmq_connect(soc.soc, s); int(i) != 0 {
return errget(err)
}
return nil
}
/*
Disconnect a socket.
For a description of endpoint, see: http://api.zeromq.org/3-2:zmq-disconnect#toc2
*/
func (soc *Socket) Disconnect(endpoint string) error {
if !soc.opened {
return ErrorSocketClosed
}
s := C.CString(endpoint)
defer C.free(unsafe.Pointer(s))
if i, err := C.zmq_disconnect(soc.soc, s); int(i) != 0 {
return errget(err)
}
return nil
}
/*
Receive a message part from a socket.
For a description of flags, see: http://api.zeromq.org/3-2:zmq-msg-recv#toc2
*/
func (soc *Socket) Recv(flags Flag) (string, error) {
b, err := soc.RecvBytes(flags)
return string(b), err
}
/*
Receive a message part from a socket.
For a description of flags, see: http://api.zeromq.org/3-2:zmq-msg-recv#toc2
*/
func (soc *Socket) RecvBytes(flags Flag) ([]byte, error) {
if !soc.opened {
return []byte{}, ErrorSocketClosed
}
var msg C.zmq_msg_t
if i, err := C.zmq_msg_init(&msg); i != 0 {
return []byte{}, errget(err)
}
defer C.zmq_msg_close(&msg)
size, err := C.zmq_msg_recv(&msg, soc.soc, C.int(flags))
if size < 0 {
return []byte{}, errget(err)
}
if size == 0 {
return []byte{}, nil
}
data := make([]byte, int(size))
C.my_memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&msg), C.size_t(size))
return data, nil
}
/*
Send a message part on a socket.
For a description of flags, see: http://api.zeromq.org/3-2:zmq-send#toc2
*/
func (soc *Socket) Send(data string, flags Flag) (int, error) {
return soc.SendBytes([]byte(data), flags)
}
/*
Send a message part on a socket.
For a description of flags, see: http://api.zeromq.org/3-2:zmq-send#toc2
*/
func (soc *Socket) SendBytes(data []byte, flags Flag) (int, error) {
if !soc.opened {
return 0, ErrorSocketClosed
}
d := data
if len(data) == 0 {
d = []byte{0}
}
size, err := C.zmq_send(soc.soc, unsafe.Pointer(&d[0]), C.size_t(len(data)), C.int(flags))
if size < 0 {
return int(size), errget(err)
}
return int(size), nil
}
/*
Register a monitoring callback.
See: http://api.zeromq.org/3-2:zmq-socket-monitor#toc2
WARNING: Closing a context with a monitoring callback will lead to random crashes.
This is a bug in the ZeroMQ library.
The monitoring callback has the same context as the socket it was created for.
Example:
package main
import (
zmq "github.com/pebbe/zmq3"
"log"
"time"
)
func rep_socket_monitor(addr string) {
s, err := zmq.NewSocket(zmq.PAIR)
if err != nil {
log.Fatalln(err)
}
err = s.Connect(addr)
if err != nil {
log.Fatalln(err)
}
for {
a, b, c, err := s.RecvEvent(0)
if err != nil {
log.Println(err)
break
}
log.Println(a, b, c)
}
s.Close()
}
func main() {
// REP socket
rep, err := zmq.NewSocket(zmq.REP)
if err != nil {
log.Fatalln(err)
}
// REP socket monitor, all events
err = rep.Monitor("inproc://monitor.rep", zmq.EVENT_ALL)
if err != nil {
log.Fatalln(err)
}
go rep_socket_monitor("inproc://monitor.rep")
// Generate an event
rep.Bind("tcp://*:5555")
if err != nil {
log.Fatalln(err)
}
// Allow some time for event detection
time.Sleep(time.Second)
rep.Close()
zmq.Term()
}
*/
func (soc *Socket) Monitor(addr string, events Event) error {
if !soc.opened {
return ErrorSocketClosed
}
if addr == "" {
if i, err := C.zmq_socket_monitor(soc.soc, nil, C.int(events)); i != 0 {
return errget(err)
}
return nil
}
s := C.CString(addr)
defer C.free(unsafe.Pointer(s))
if i, err := C.zmq_socket_monitor(soc.soc, s, C.int(events)); i != 0 {
return errget(err)
}
return nil
}
/*
Receive a message part from a socket interpreted as an event.
For a description of flags, see: http://api.zeromq.org/3-2:zmq-msg-recv#toc2
For a description of event_type, see: http://api.zeromq.org/3-2:zmq-socket-monitor#toc2
For an example, see: func (*Socket) Monitor
*/
func (soc *Socket) RecvEvent(flags Flag) (event_type Event, addr string, value int, err error) {
if !soc.opened {
return EVENT_ALL, "", 0, ErrorSocketClosed
}
var msg C.zmq_msg_t
if i, e := C.zmq_msg_init(&msg); i != 0 {
err = errget(e)
return
}
defer C.zmq_msg_close(&msg)
size, e := C.zmq_msg_recv(&msg, soc.soc, C.int(flags))
if size < 0 {
err = errget(e)
return
}
var t C.zmq_event_t
if size < C.int(unsafe.Sizeof(t)) {
err = ErrorNoEvent
return
}
et := C.int(0)
val := C.int(0)
addrs := C.get_event(&msg, &et, &val)
defer C.free(unsafe.Pointer(addrs))
event_type = Event(et)
addr = C.GoString(addrs)
value = int(val)
return
}
/*
Start built-in ØMQ proxy
See: http://api.zeromq.org/3-2:zmq-proxy
*/
func Proxy(frontend, backend, capture *Socket) error {
if !(frontend.opened && backend.opened && (capture == nil || capture.opened)) {
return ErrorSocketClosed
}
var capt unsafe.Pointer
if capture != nil {
capt = capture.soc
}
_, err := C.zmq_proxy(frontend.soc, backend.soc, capt)
return errget(err)
}