1. james woodyatt
  2. oni

Commits

jhwoodyatt  committed 14825c7

Submit cf-0.1 release.

  • Participants
  • Parent commits 812e091
  • Branches default

Comments (0)

Files changed (5)

File cf/cf_ip6_proto_p.h

View file
  • Ignore whitespace
 /*---------------------------------------------------------------------------*
   C HEADER  cf_ip6_proto_p.h
 
-  Copyright (c) 2003, James H. Woodyatt
+  Copyright (c) 2003-2004, James H. Woodyatt
   All rights reserved.
 
   Redistribution and use in source and binary forms, with or without
 
 #include "cf_ip_common_p.h"
 
-#define Cf_ip6_sockaddr_val(v)  ((struct sockaddr_in6*) Data_custom_val(v))
-extern value cf_ip6_sockaddr_alloc(const struct sockaddr_in6* addrPtr);
+Cf_socket_sockaddrx_struct(in6);
+Cf_socket_sockaddrx_typedef(in6);
 
 #endif /* defined(_CF_IP6_PROTO_P_H) */
 

File cf/cf_ip_common.ml

View file
  • Ignore whitespace
 (*---------------------------------------------------------------------------*
   IMPLEMENTATION  cf_ip_common.ml
 
-  Copyright (c) 2003, James H. Woodyatt
+  Copyright (c) 2003-2004, James H. Woodyatt
   All rights reserved.
 
   Redistribution and use in source and binary forms, with or without
   OF THE POSSIBILITY OF SUCH DAMAGE. 
  *---------------------------------------------------------------------------*)
 
+external init_: unit -> unit = "cf_ip_common_init";;
+init_ ();;
+
 type protocol_number_t =
-    P_zero | P_icmp | P_ipv4 | P_tcp | P_udp
+    P_zero | P_icmp | P_ipv4 | P_ipv6 | P_tcp | P_udp
 
 external protocol_:
     protocol_number_t -> Cf_socket.protocol_t = "cf_ip_common_protocol"
 let zero = protocol_ P_zero
 let icmp = protocol_ P_icmp
 let ipv4 = protocol_ P_ipv4
+let ipv6 = protocol_ P_ipv6
 let tcp = protocol_ P_tcp
 let udp = protocol_ P_udp
 
+type sockopt_index_t = TCP_NODELAY
+
+external sockopt_lift:
+    sockopt_index_t -> ('v,[<`AF_INET|`AF_INET6],'st) Cf_socket.sockopt_t =
+    "cf_ip_common_sockopt_lift"
+
+let tcp_nodelay = Obj.magic (sockopt_lift TCP_NODELAY)
+
 (*--- End of File [ cf_ip_common.ml ] ---*)

File cf/cf_ip_common.mli

View file
  • Ignore whitespace
 (*---------------------------------------------------------------------------*
   INTERFACE  cf_ip_common.mli
 
-  Copyright (c) 2003, James H. Woodyatt
+  Copyright (c) 2003-2004, James H. Woodyatt
   All rights reserved.
 
   Redistribution and use in source and binary forms, with or without
 (** The Internet Protocol (version 4) for tunneling. *)
 val ipv4: Cf_socket.protocol_t
 
+(** The Internet Protocol (version 6) for tunneling. *)
+val ipv6: Cf_socket.protocol_t
+
 (** The Internet Transmission Control Protocol. *)
 val tcp: Cf_socket.protocol_t
 
 (** The Internet User Datagram Protocol. *)
 val udp: Cf_socket.protocol_t
 
+(** {6 Socket Options}
+
+    The following socket options are available on sockets of AF_INET and
+    AF_INET6 address/protocol families.
+*)
+
+(** Disables the Nagle algorithm for TCP connections. *)
+val tcp_nodelay:
+    (bool, [< `AF_INET | `AF_INET6 ], [ `SOCK_STREAM ]) Cf_socket.sockopt_t
+
 (*--- End of File [ cf_ip_common.mli ] ---*)

File cf/cf_ip_common_p.c

View file
  • Ignore whitespace
 /*---------------------------------------------------------------------------*
   C MODULE  cf_ip_common_p.c
 
-  Copyright (c) 2003, James H. Woodyatt
+  Copyright (c) 2003-2004, James H. Woodyatt
   All rights reserved.
 
   Redistribution and use in source and binary forms, with or without
 
 #include "cf_ip_common_p.h"
 
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+
 /*---
     type protocol_number_t =
-        P_zero | P_icmp | P_ipv4 | P_tcp | P_udp
+        P_zero | P_icmp | P_ipv4 | P_ipv6 | P_tcp | P_udp
     
     external protocol_:
         protocol_number_t -> Cf_socket.protocol_t = "cf_ip_common_protocol"
     static const int protocol[] = {
         /* P_zero */	0,
         /* P_icmp */	IPPROTO_ICMP,
-        /* P_ipv4 */	IPPROTO_IPV4,
+        /* P_ipv4 */	IPPROTO_IP,
+        /* P_ipv6 */	IPPROTO_IPV6,
         /* P_tcp */     IPPROTO_TCP,
         /* P_udp */     IPPROTO_UDP,
     };
     CAMLreturn(copy_nativeint(protocol[Int_val(numVal)]));
 }
 
+/*---
+    type sockopt_index_t = TCP_NODELAY
+  ---*/
+static Cf_socket_sockopt_lift_t cf_ip_common_sockopt_lift_array[] = {
+    { /* TCP_NODELAY */
+        Val_unit,
+        {
+            IPPROTO_TCP, TCP_NODELAY,
+            cf_socket_getsockopt_bool, cf_socket_setsockopt_bool
+        }
+    },
+};
+
+#define CF_IP_COMMON_SOCKOPT_LIFT_ARRAY_SIZE \
+    (sizeof cf_ip_common_sockopt_lift_array / \
+        sizeof cf_ip_common_sockopt_lift_array[0])
+
+/*---
+    external sockopt_lift:
+        sockopt_index_t -> ('a,[<`AF_INET|`AF_INET6],'c) Cf_socket.sockopt_t =
+        "cf_ip_common_sockopt_lift"
+  ---*/
+CAMLprim value cf_ip_common_sockopt_lift(value indexVal)
+{
+    CAMLparam1(indexVal);
+    CAMLreturn(cf_ip_common_sockopt_lift_array[Int_val(indexVal)].ol_val);
+}
+
+/*---
+  Initialization primitive
+  ---*/
+CAMLprim value cf_ip_common_init(value unit)
+{
+    int i;
+            
+    for (i = 0; i < CF_IP_COMMON_SOCKOPT_LIFT_ARRAY_SIZE; ++i) {        
+        Cf_socket_sockopt_lift_t* liftPtr;
+        
+        liftPtr = &cf_ip_common_sockopt_lift_array[i];
+        register_global_root(&liftPtr->ol_val);
+        liftPtr->ol_val = cf_socket_option_alloc(&liftPtr->ol_option);
+    }
+
+    return Val_unit;
+}
 
 /*--- End of File [ cf_ip_common_p.c ] ---*/

File cf/cf_ip_common_p.h

View file
  • Ignore whitespace
 /*---------------------------------------------------------------------------*
   C HEADER  cf_ip_common_p.h
 
-  Copyright (c) 2003, James H. Woodyatt
+  Copyright (c) 2003-2004, James H. Woodyatt
   All rights reserved.
 
   Redistribution and use in source and binary forms, with or without
 #include "cf_ip6_addr_p.h"
 #include "cf_socket_p.h"
 
-#include <sys/types.h>
-#include <sys/socket.h>
-
 #endif /* defined(_CF_IP_COMMON_P_H) */
 
 /*--- End of File [ cf_ip_common_p.h ] ---*/