


## socket.api
# Compiled by:
# src/lib/std/src/standard-core.sublibstipulate
package os= winix_guts; # winix_guts is from src/lib/std/src/posix/winix-guts.pkgherein
# We start with a version of this api that does not contain
# any of the non-blocking operations:
#
api Synchronous_Socket {
# Sockets are typeagnostic; the instantiation of the type variables
# provides a way to distinguish between different kinds of sockets.
#
Socket( A_af, A_sock_type );
Socket_Address( A_af );
# Witness types for the socket parameter:
#
Datagram;
Stream( A_mode );
Passive; # for passive streams
Active; # for active (connected) streams
# Address families
#
package af
:
api {
Address_Family
=
dns_host_lookup::Address_Family;
list: Void -> List ((String, Address_Family)); # list known address families
to_string: Address_Family -> String;
from_string: String -> Null_Or( Address_Family );
};
# Socket types:
#
package socket
:
api {
eqtype Socket_Type;
stream: Socket_Type; # Stream sockets
datagram: Socket_Type; # Datagram sockets
list: Void -> List ((String, Socket_Type)); # list known socket types
to_string: Socket_Type -> String;
from_string: String -> Null_Or( Socket_Type );
};
# Socket control operations:
#
package control
:
api {
# get/set socket options
#
get_debug: Socket( A_af, A_sock_type ) -> Bool;
set_debug: (Socket( A_af, A_sock_type ), Bool) -> Void;
get_reuseaddr: Socket( A_af, A_sock_type ) -> Bool;
set_reuseaddr: (Socket( A_af, A_sock_type ), Bool) -> Void;
get_keepalive: Socket( A_af, A_sock_type ) -> Bool;
set_keepalive: (Socket( A_af, A_sock_type ), Bool) -> Void;
get_dontroute: Socket( A_af, A_sock_type ) -> Bool;
set_dontroute: (Socket( A_af, A_sock_type ), Bool) -> Void;
get_linger: Socket( A_af, A_sock_type ) -> Null_Or( time::Time );
set_linger: (Socket( A_af, A_sock_type ), Null_Or( time::Time )) -> Void;
get_broadcast: Socket( A_af, A_sock_type ) -> Bool;
set_broadcast: (Socket( A_af, A_sock_type ), Bool) -> Void;
get_oobinline: Socket( A_af, A_sock_type ) -> Bool;
set_oobinline: (Socket( A_af, A_sock_type ), Bool) -> Void;
get_sndbuf: Socket( A_af, A_sock_type ) -> Int;
set_sndbuf: (Socket( A_af, A_sock_type ), Int) -> Void;
get_rcvbuf: Socket( A_af, A_sock_type ) -> Int;
set_rcvbuf: (Socket( A_af, A_sock_type ), Int) -> Void;
get_type: Socket( A_af, A_sock_type ) -> socket::Socket_Type;
get_error: Socket( A_af, A_sock_type ) -> Bool;
get_peer_name: Socket( A_af, A_sock_type ) -> Socket_Address( A_af );
get_sock_name: Socket( A_af, A_sock_type ) -> Socket_Address( A_af );
get_nread: Socket( A_af, A_sock_type ) -> Int;
get_atmark: Socket( A_af, Stream( Active ) ) -> Bool;
};
# Socket address operations:
#
same_address: (Socket_Address( A_af ), Socket_Address( A_af )) -> Bool;
family_of_address: Socket_Address( A_af ) -> af::Address_Family;
# Socket management:
#
bind: (Socket( A_af, A_sock_type ), Socket_Address( A_af )) -> Void;
listen: (Socket( A_af, Stream( Passive ) ), Int) -> Void;
accept: Socket( A_af, Stream( Passive ) )
-> (Socket( A_af, Stream( Active ) ), Socket_Address( A_af ));
connect: (Socket( A_af, A_sock_type ), Socket_Address( A_af )) -> Void;
close: Socket( A_af, A_sock_type ) -> Void;
Shutdown_Mode = NO_RECVS | NO_SENDS | NO_RECVS_OR_SENDS;
shutdown: (Socket( A_af, Stream( A_mode ) ), Shutdown_Mode) -> Void;
Socket_Descriptor;
socket_descriptor: Socket( A_af, A_sock_type ) -> Socket_Descriptor;
same_descriptor: (Socket_Descriptor, Socket_Descriptor) -> Bool;
# See also the 'wait_for_io_opportunity' operation in src/lib/std/src/winix/winix-io.api #
wait_for_io_opportunity
:
{ readable: List( Socket_Descriptor ),
writable: List( Socket_Descriptor ),
oobdable: List( Socket_Descriptor ),
timeout: Null_Or( time::Time ) }
->
{ readable: List( Socket_Descriptor ), # Sockets on which a read() will not block.
writable: List( Socket_Descriptor ), # Sockets on which a write() will not block.
oobdable: List( Socket_Descriptor ) # Sockets with out-of-band data available, (PTY packet-mode control status data).
};
# Deprecated synonym for above, mainly so that unix folks
# looking for 'select' in the function index will get led here:
#
select
:
{ readable: List( Socket_Descriptor ),
writable: List( Socket_Descriptor ),
oobdable: List( Socket_Descriptor ),
timeout: Null_Or( time::Time ) }
->
{ readable: List( Socket_Descriptor ), # Sockets on which a read() will not block.
writable: List( Socket_Descriptor ), # Sockets on which a write() will not block.
oobdable: List( Socket_Descriptor ) # Sockets with out-of-band data available, (PTY packet-mode control status data).
};
io_descriptor
:
Socket( A_af, A_sock_type )
->
os::io::Io_Descriptor;
# Socket I/O option types
#
Out_Flags = { oob: Bool, don't_route: Bool };
In_Flags = { oob: Bool, peek: Bool };
# Socket output operations
#
send_vector : (Socket(A_af, Stream(Active)), vector_slice_of_one_byte_unts::Slice ) -> Int;
send_rw_vector : (Socket(X, Stream(Active)), rw_vector_slice_of_one_byte_unts::Slice ) -> Int;
send_vector' : (Socket(X, Stream(Active)), vector_slice_of_one_byte_unts::Slice, Out_Flags) -> Int;
send_rw_vector' : (Socket(X, Stream(Active)), rw_vector_slice_of_one_byte_unts::Slice, Out_Flags) -> Int;
send_vector_to : (Socket(X, Datagram), Socket_Address(X), vector_slice_of_one_byte_unts::Slice ) -> Void;
send_rw_vector_to : (Socket(X, Datagram), Socket_Address(X), rw_vector_slice_of_one_byte_unts::Slice ) -> Void;
send_vector_to' : (Socket(X, Datagram), Socket_Address(X), vector_slice_of_one_byte_unts::Slice, Out_Flags) -> Void;
send_rw_vector_to' : (Socket(X, Datagram), Socket_Address(X), rw_vector_slice_of_one_byte_unts::Slice, Out_Flags) -> Void;
# Socket input operations
#
receive_vector : (Socket(X, Stream(Active)), Int ) -> vector_of_one_byte_unts::Vector;
receive_rw_vector : (Socket(X, Stream(Active)), rw_vector_slice_of_one_byte_unts::Slice ) -> Int;
receive_vector' : (Socket(X, Stream(Active)), Int, In_Flags) -> vector_of_one_byte_unts::Vector;
receive_rw_vector' : (Socket(X, Stream(Active)), rw_vector_slice_of_one_byte_unts::Slice, In_Flags) -> Int;
receive_vector_from: (Socket(X, Datagram), Int) -> (vector_of_one_byte_unts::Vector, Socket_Address(Y));
receive_rw_vector_from: (Socket(X, Datagram), rw_vector_slice_of_one_byte_unts::Slice) -> (Int, Socket_Address(X));
receive_vector_from' : (Socket(X, Datagram), Int, In_Flags) -> (vector_of_one_byte_unts::Vector, Socket_Address(Y));
receive_rw_vector_from' : (Socket(X, Datagram), rw_vector_slice_of_one_byte_unts::Slice, In_Flags) -> (Int, Socket_Address(X));
};
# Add non-blocking ops:
#
api Socket {
include Synchronous_Socket; # See above.
accept_nonblocking: Socket( A_af, Stream(Passive) ) -> Null_Or( (Socket( A_af, Stream(Active) ), Socket_Address(A_af)));
connect_nonblocking: (Socket( A_af, A_sock_type ), Socket_Address( A_af )) -> Bool;
send_vector_nonblocking : (Socket(A_af, Stream(Active)), vector_slice_of_one_byte_unts::Slice) -> Null_Or( Int );
send_rw_vector_nonblocking : (Socket(X, Stream(Active)), rw_vector_slice_of_one_byte_unts::Slice) -> Null_Or( Int );
send_vector_nonblocking' : (Socket(X, Stream(Active)), vector_slice_of_one_byte_unts::Slice, Out_Flags) -> Null_Or( Int );
send_rw_vector_nonblocking' : (Socket(X, Stream(Active)), rw_vector_slice_of_one_byte_unts::Slice, Out_Flags) -> Null_Or( Int );
send_vector_to_nonblocking : (Socket(X, Datagram), Socket_Address(X), vector_slice_of_one_byte_unts::Slice ) -> Bool;
send_rw_vector_to_nonblocking : (Socket(X, Datagram), Socket_Address(X), rw_vector_slice_of_one_byte_unts::Slice ) -> Bool;
send_vector_to_nonblocking' : (Socket(X, Datagram), Socket_Address(X), vector_slice_of_one_byte_unts::Slice, Out_Flags) -> Bool;
send_rw_vector_to_nonblocking': (Socket(X, Datagram), Socket_Address(X), rw_vector_slice_of_one_byte_unts::Slice, Out_Flags) -> Bool;
receive_vector_nonblocking : (Socket(X, Stream(Active)), Int ) -> Null_Or( vector_of_one_byte_unts::Vector );
receive_rw_vector_nonblocking : (Socket(X, Stream(Active)), rw_vector_slice_of_one_byte_unts::Slice ) -> Null_Or( Int );
receive_vector_nonblocking' : (Socket(X, Stream(Active)), Int, In_Flags) -> Null_Or( vector_of_one_byte_unts::Vector );
receive_rw_vector_nonblocking': (Socket(X, Stream(Active)), rw_vector_slice_of_one_byte_unts::Slice, In_Flags) -> Null_Or( Int );
receive_vector_from_nonblocking : (Socket(X, Datagram), Int ) -> Null_Or( (vector_of_one_byte_unts::Vector, Socket_Address(Y)) );
receive_rw_vector_from_nonblocking : (Socket(X, Datagram), rw_vector_slice_of_one_byte_unts::Slice ) -> Null_Or( (Int, Socket_Address(X)) );
receive_vector_from_nonblocking' : (Socket(X, Datagram), Int, In_Flags) -> Null_Or( (vector_of_one_byte_unts::Vector, Socket_Address(Y)) );
receive_rw_vector_from_nonblocking': (Socket(X, Datagram), rw_vector_slice_of_one_byte_unts::Slice, In_Flags) -> Null_Or( (Int, Socket_Address(X)) );
};
end;
## COPYRIGHT (c) 1995 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2012,
## released under Gnu Public Licence version 3.


