NAME

/precompiled/port - a program for handling and listening to open ports

DESCRIPTION

/precompiled/port is a precompiled program that handles listening to sockets. Whenever you need a bound socket that is open and listens for connections you should use this program.

Here follows the diescriptionsof the functions in /precompiled/port:


NAME

bind - open socket and bind it to a port

SYNTAX

int port->bind(int port);
or
int port->bind(int port,function accept_callback);
or
int port->bind(int port,function accept_callback, string ip);

DESCRIPTION

Bind opens a sockets and binds it to port number on the local machine. If the second argument is present, the socket is set to nonblocking and the callback funcition is called whenever something connects to the socket. The callback will receive the id for this port as argument. Bind returns 1 on success, and zero on failiure.

If the optional argument 'ip' is given, bind will try to bind to this ip name (or number).

SEE ALSO

port->accept


NAME

listen_fd - listen to an already open port

SYNTAX

int port->listen_fd(int fd);
or
int port->listen_fd(int fd,function accept_callback);

DESCRIPTION

This function does the same as port->bind, except that instead of creating a new socket and bind it to a port, it expects that the filedescriptor 'fd' is an alread open port.

NOTA BENE

This function is only for the advanced user, and is generally used when sockets are passed to uLPC at exec time.

SEE ALSO

port->bind and port->accept


NAME

create - create and/or setup a port

SYNTAX

void port->create("stdin")
or
void port->create("stdin",function accept_callback)
or
void port->create("stdin",function accept_callback)
or
void port->create(int port)
or
void port->create(int port,function accept_callback)
or
void port->create(int port,function accept_callback, string ip)

DESCRIPTION

When create is called with 'stdin' as argument, a socket is created out of the file descriptor 0, this is only useful if that actually IS a socket to begin with. When create is called with an int as first argument, it does the same as bind() would do with the same arguments.

SEE ALSO

clone


NAME

set_id - set the id of a port

SYNTAX

void port->set_id(mixed id);

DESCRIPTION

This function sets the id used for accept_callback by this port. The default id is this_object().

SEE ALSO

port->query_id


NAME

query_id - Return the id for this port.

SYNTAX

mixed port->query_id();

DESCRIPTION

This function returns the id for this port. The id is normally the first argument to accept_callback.

SEE ALSO

port->set_id


NAME

errno - return the last error

SYNTAX

int port->errno();

DESCRIPTION

If the last call done on this port failed, errno will return an integer describing what went wrong. Refer to your unix manual for further information.

SEE ALSO

file->errno


NAME

accept - accept a connection

SYNTAX

object port->accept();

DESCRIPTION

This function completes a connection made from a remote machine to this port. It returns a two-way stream in the form of a copy of /precompiled/file. The new file is by default set to blocking.

SEE ALSO

/precompiled/file