aboutsummaryrefslogtreecommitdiff
path: root/network.go
diff options
context:
space:
mode:
Diffstat (limited to 'network.go')
-rw-r--r--network.go52
1 files changed, 33 insertions, 19 deletions
diff --git a/network.go b/network.go
index 52f4ee4..0440326 100644
--- a/network.go
+++ b/network.go
@@ -140,6 +140,19 @@ func (self MsgNetwork) Listen(addr NetAddr, err *Error) { C.msgnetwork_listen(se
// Stop the message network. No other methods should be called after this.
func (self MsgNetwork) Stop() { C.msgnetwork_stop(self.inner) }
+// Send a message through the given connection.
+func (self MsgNetwork) SendMsg(msg Msg, conn MsgNetworkConn) {
+ C.msgnetwork_send_msg(self.inner, msg.inner, conn.inner)
+}
+
+// Send a message through the given connection, using a worker thread to
+// seralize and put data to the send buffer. The payload contained in the given
+// msg will be moved and sent. Thus, no methods of msg involving the payload
+// should be called afterwards.
+func (self MsgNetwork) SendMsgDeferredByMove(msg Msg, conn MsgNetworkConn) {
+ C.msgnetwork_send_msg_deferred_by_move(self.inner, msg.inner, conn.inner)
+}
+
// Try to connect to a remote address. The connection handle is returned. The
// returned connection handle could be kept in your program.
func (self MsgNetwork) Connect(addr NetAddr, err *Error) MsgNetworkConn {
@@ -151,11 +164,6 @@ func (self MsgNetwork) Connect(addr NetAddr, err *Error) MsgNetworkConn {
// Terminate the given connection.
func (self MsgNetwork) Terminate(conn MsgNetworkConn) { C.msgnetwork_terminate(self.inner, conn.inner) }
-// Send a message through the given connection. The payload contained in the
-// given msg will be moved and sent. Thus, no methods of msg involving the
-// payload should be called afterwards.
-func (self MsgNetwork) SendMsgByMove(msg Msg, conn MsgNetworkConn) { C.msgnetwork_send_msg_by_move(self.inner, msg.inner, conn.inner) }
-
// The C function pointer type which takes msg_t*, msgnetwork_conn_t* and void*
// (passing in the custom user data allocated by C.malloc) as parameters.
type MsgNetworkMsgCallback = C.msgnetwork_msg_callback_t
@@ -322,26 +330,32 @@ func (self PeerNetworkConn) Copy() PeerNetworkConn {
func (self PeerNetworkConn) free() { C.peernetwork_conn_free(self.inner) }
-// Send a message to the given peer. The payload contained in the given msg
-// will be moved and sent. Thus, no methods of msg involving the payload should
-// be called afterwards.
-func (self PeerNetwork) SendMsgByMove(_moved_msg Msg, paddr NetAddr) {
- C.peernetwork_send_msg_by_move(self.inner, _moved_msg.inner, paddr.inner)
+// Listen to the specified network address. Notice that this method overrides
+// Listen() in MsgNetwork, so you should always call this one instead of
+// AsMsgNetwork().Listen().
+func (self PeerNetwork) Listen(listenAddr NetAddr, err *Error) {
+ C.peernetwork_listen(self.inner, listenAddr.inner, err)
+}
+
+// Send a message to the given peer.
+func (self PeerNetwork) SendMsg(msg Msg, addr NetAddr) {
+ C.peernetwork_send_msg(self.inner, msg.inner, addr.inner)
+}
+
+// Send a message to the given peer, using a worker thread to seralize and put
+// data to the send buffer. The payload contained in the given msg will be
+// moved and sent. Thus, no methods of msg involving the payload should be
+// called afterwards.
+func (self PeerNetwork) SendMsgDeferredByMove(msg Msg, addr NetAddr) {
+ C.peernetwork_send_msg_deferred_by_move(self.inner, msg.inner, addr.inner)
}
// Send a message to the given list of peers. The payload contained in the
// given msg will be moved and sent. Thus, no methods of msg involving the
// payload should be called afterwards.
-func (self PeerNetwork) MulticastMsgByMove(_moved_msg Msg, paddrs []NetAddr) {
+func (self PeerNetwork) MulticastMsgByMove(msg Msg, paddrs []NetAddr) {
na := NewAddrArrayFromAddrs(paddrs)
- C.peernetwork_multicast_msg_by_move(self.inner, _moved_msg.inner, na.inner)
-}
-
-// Listen to the specified network address. Notice that this method overrides
-// Listen() in MsgNetwork, so you should always call this one instead of
-// AsMsgNetwork().Listen().
-func (self PeerNetwork) Listen(listenAddr NetAddr, err *Error) {
- C.peernetwork_listen(self.inner, listenAddr.inner, err)
+ C.peernetwork_multicast_msg_by_move(self.inner, msg.inner, na.inner)
}
// The C function pointer type which takes netaddr_t* and void* (passing in the