12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455moduletypeS=sig(** A low-level socket interface, common to both Windows and Linux kernels *)typettypesockaddr(** A socket address *)valstring_of_sockaddr:sockaddr->stringvalcreate:unit->t(** [create ()] creates an unbound socket *)valbind:t->sockaddr->unit(** [bind socket sockaddr] binds [socket] to [sockaddr] *)vallisten:t->int->unit(** [listen socket queue_length] sets the socket to listening mode with the
given maximum queue length *)valaccept:t->t*sockaddr(** [accept fd] accepts a single connection *)valconnect:?timeout_ms:int->t->sockaddr->unit(** [connect ?timeout_ms fd sockaddr] connects to a remote socket.
On Windows the raw connect call can block forever if the server is not
running when the call is executed (even if the server starts up afterwards)
there is a default timeout of 300ms. On timeout this will raise
[Unix_error(Unix.ETIMEDOUT)] *)valwritev:t->Cstruct.tlist->int(** Write a list of buffers *)valread_into:t->Cstruct.t->int(** Read into a buffer, returning the number of bytes written *)valshutdown_read:t->unit(** Close the read half of the connection *)valshutdown_write:t->unit(** Close the write half of the connection *)valclose:t->unit(** Close both halves of the connection *)endtypebuffer=(char,Bigarray.int8_unsigned_elt,Bigarray.c_layout)Bigarray.Array1.texternalstub_ba_sendv:Unix.file_descr->(buffer*int*int)list->int="stub_hvsock_ba_sendv"externalstub_ba_recv:Unix.file_descr->buffer->int->int->int="stub_hvsock_ba_recv"letwritevfdbs=letbs'=List.map(funb->b.Cstruct.buffer,b.Cstruct.off,b.Cstruct.len)bsinstub_ba_sendvfdbs'letread_intofdb=stub_ba_recvfdb.Cstruct.bufferb.Cstruct.offb.Cstruct.len