chiark / gitweb /
transmits
authorian <ian>
Sat, 7 Sep 2002 01:23:16 +0000 (01:23 +0000)
committerian <ian>
Sat, 7 Sep 2002 01:23:16 +0000 (01:23 +0000)
base/tables-examples.tct
dgram/dgram.c

index 6f8755a..f402a4c 100644 (file)
@@ -91,5 +91,7 @@ Table dgram_socket DgramSocket_SubCommand
                =>      sockid
        close
                sock    sockid
-#      transmit
-#              
+       transmit
+               sock    sockid
+               data    hb
+               remote  sockaddr
index e6df127..7e98df2 100644 (file)
@@ -4,8 +4,9 @@
  * dgram-socket create <local>                        => <sockid>
  * dgram-socket close <sockid>
  * dgram-socket transmit <sockid> <data> <remote>
- * dgram-socket on-receive <sockid> <script>
+ * dgram-socket on-receive <sockid> [<script>]
  *    calls, effectively,  eval <script> [list <data> <remote-addr> <socket>]
+ *    if script not supplied, cancel
  */
 
 #include "tables.h"
@@ -52,6 +53,20 @@ int do_dgram_socket_create(ClientData cd, Tcl_Interp *ip,
   return TCL_OK;
 }
 
+int do_dgram_socket_transmit(ClientData cd, Tcl_Interp *ip,
+                            int sock, HBytes_Value data,
+                            SockAddr_Value remote) {
+  int l, r;
+
+  r= sendto(socks[sock].fd,
+           hbytes_data(&data), l=hbytes_len(&data),
+           0,
+           sockaddr_addr(&remote), sockaddr_len(&remote));
+  if (r==-1) return posixerr(ip,errno,"sendto");
+  else if (r!=l) return staticerr(ip,"sendto gave wrong answer");
+  return TCL_OK;
+}
+  
 int do_dgram_socket_close(ClientData cd, Tcl_Interp *ip, int sock) {
   close(socks[sock].fd); /* nothing useful to be done with errors */
   socks[sock].fd= -1;