## socket-junk.api
# Compiled by:
#
src/lib/std/standard.lib# Various utility functions for programming with sockets.
stipulate
package sok = socket__premicrothread; # socket__premicrothread is from
src/lib/std/socket--premicrothread.pkgherein
api Socket_Junk {
#
Port = PORT_NUMBER Int
| SERV_NAME String
;
#
# A port can be identified by number, or by the name of a service
Hostname = HOST_NAME String
| HOST_ADDRESS dns_host_lookup::Internet_Address
;
scan_addr
:
number_string::Reader (Char, X)
->
number_string::Reader ( { host: Hostname, port: Null_Or( Port ) }, X);
# scan an address, which has the form
# address [ ":" port ]
# where the address may either be numeric or symbolic host name and the
# port is either a service name or a decimal number. Legal host names
# must begin with a letter, and may contain any alphanumeric character,
# the minus sign (-) and period (.), where the period is used as a
# domain separator.
addr_from_string: String -> Null_Or { host: Hostname, port: Null_Or( Port ) };
exception BAD_ADDRESS String;
resolve_addr
:
{ host: Hostname,
port: Null_Or( Port )
}
->
{ host: String,
address: dns_host_lookup::Internet_Address,
port: Null_Or( Int )
};
#
# Given a hostname and optional port, resolve them in the host
# and service database. If either the host or service name is not
# found, then BAD_ADDRESS is raised.
Stream_Socket(X)
=
sok::Socket (X, sok::Stream( sok::Active ));
connect_client_to_internet_domain_stream_socket
:
{ address: dns_host_lookup::Internet_Address,
port: Int
}
->
Stream_Socket( internet_socket__premicrothread::Inet );
#
# Establish a client-side connection to a INET domain stream socket
receive_vector: ((Stream_Socket(X), Int) ) -> vector_of_one_byte_unts::Vector;
receive_string: ((Stream_Socket(X), Int) ) -> String;
send_vector: ((Stream_Socket(X), vector_of_one_byte_unts::Vector) ) -> Void;
send_string: ((Stream_Socket(X), String) ) -> Void;
send_rw_vector: ((Stream_Socket(X), rw_vector_of_one_byte_unts::Rw_Vector)) -> Void;
};
end;
## COPYRIGHT (c) 1996 AT&T Research.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.