TCP/IP Functions (not included in filePro Lite)

handle2 = ACCEPT(handle)

 

Accept a connection on a socket. Returns a positive number  containing the new handle, zero indicating no more sockets are available, or a negative number containing the error number.

 

status = BIND(handle,port [ ,address [ ,family ]] )

 

Binds a name to a socket. Note that the parameters are not identical to the C bind() function, but the port/address/family correspond to the struct sockaddr_in members sin_port, sin_addr, and sin_family, respectively. Port can be given by a number, or a name defined in /etc/services. Address can be an IP address, or any name known to the DNS server, or null for INADDR_ANY. Family defaults to AF_INET. Returns zero on success, or a negative number containing the error number.

 

status = CONNECT(handle,port,address [ ,family ] )

 

Initiate a connection on a socket. Note that the parameters are not identical to the C bind() function, but the port/address/family correspond to the struct sockaddr_in members sin_port, sin_addr, and sin_family, respectively. Port can be given by a number, or a name defined in /etc/services. Address can be an IP address, or any name known to the DNS server, or null for INADDR_ANY. Family defaults to AF_INET. Returns zero on success, or a negative number containing the error number.

 

name = GETPEERNAME(handle)

Returns the name of the connected peer, or "" on failure.

 

name = GETSOCKNAME(handle)

Returns the name of the socket, or "" on failure.

 

status = LISTEN(handle [ ,backlog ] )

 

Listen for connections on a socket. Backlog defines the maximum length to which the queue of pending connections may grow, and defaults to 1. Returns zero on success, or a negative number containing the error number.

 

status = RECV(handle,dest [ ,len [ ,flags [ ,noblock ]]] )

status = RECVLINE(handle,dest [ ,len [ ,flags [ ,noblock ]]] )

 

Receive a message from a connected socket. Fills in the field in "dest" with the result. Returns the number of characters received, or a negative number containing the error number. A maximum of "len" characters will be read. RECVLINE() will read up to len characters, or until a new line character is received. The new line character, if any, will be discarded for RECVLINE(). "Len" defaults to the length of the destination field. "Flags" defaults to zero and should currently not be given any other value. "Noblock" defaults to zero. It a non-zero value is passed, the function will return immediately, even if less than "len" bytes are received.

 

status = SELECT( nhandle [ ,read_array [ ,write_array [ ,except_array [ ,timeout ]]]] )

where

nhandle = Maximum number of handles to use from each array.  If the array is shorter than nhandle, then the entire array is used.  Array entries of zero are ignored.

read_array = Name of array holding handles to check for read.

write_array = Name of array holding handles to check for write.

except_array = Name of array holding handles to check for exceptions.

timeout = Timeout, in microseconds.

Notes:  If timeout is not specified, or is zero length, the function will not return until at least one handle meets the specified criteria.  A timeout of zero means it will return immediately, regardless of the states of the handles.  (This is one of the rare instances in filePro where a null numeric value is not the same as zero.  This is part of the functionality of the select system call, which is duplicated in filePro's SELECT function.)
Only socket handles can be checked.  While *nix systems allow any file handle to be passed to select(), Windows allows only socket handles.  A future filePro update may allow non-socket handles to be passed to SELECT().

 

status = @SELECT.READ(handle)
status = @SELECT.WRITE(handle)
status = @SELECT.EXCEPT(handle)

 

After executing a SELECT(), these functions are used to determine if the specified handle satisfied the select criteria.  The return value is either "0" for false, and "1" for true.  For example, @SELECT.READ(MySocket) will return "1" if MySocket has data ready for reading.  (Assuming, of course, that MySocket was in the read_array passed to the last SELECT function.)

Note that if the last SELECT() call did not get passed the corresponding array, the result of these functions are undefined. For example, a SELECT(nhandle,read_array,,except_array) call followed by @SELECT.WRITE(x) will be undefined, as no write_array was passed.

 

status = SEND(handle,value [ ,flags ] )

status = SENDLINE(handle,value [ ,flags ] )

 

Send a message to a connected socket. Flags defaults to zero and really shouldn't be used yet. SENDLINE() appends a newline character to the message. Returns the number of characters sent, or a negative number containing the error number.

 

handle = SOCKET( [ family [ ,type [ ,protocol ]]] )

 

Creates a socket of the specified type. Returns a positive number containing the handle to the socket, zero if there are no more sockets available, or a negative number containing  the error number.

 Note: currently, the parameters are ignored, and the socket is always (AF_INET,SOCK_STREAM,0)

 

status = SOCKETCLOSE(handle)

 

Closes the socket. (Note: even though Unix socket handles and open file handles are interchangable, this is not the case under Windows hence the requirement for a separate close function.)

As of 5.7.02. this command will now release the license used.

 

systemhandle = SOCKETTOSYS(handle)

 

Returns the corresponding system handle number for an open socket, or a negative error number if "handle" isn't a valid filePro socket.

 

errno = SOCKETERROR()

 

 Returns the error code of the last socket-related error. The number is system-dependent.

 

handle = SYSTOSOCKET(systemhandle)

 

Given an operating system handle that corresponds to a socket, this creates a filePro handle to it. (Example: a server daemon has already listen()ed and accept()ed the connection, and spawned filePro to handle the connection.) Note that there is no check that the handle is really a valid socket. Returns zero if no filePro sockets are available.