/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* File: prio.h
*
* Description: PR i/o related stuff, such as file system access, file
* i/o, socket i/o, etc.
*/
#ifndef prio_h___
#define prio_h___
#include "prlong.h"
#include "prtime.h"
#include "prinrval.h"
#include "prinet.h"
#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
/* Typedefs */
#ifdef MOZ_UNICODE
#endif /* MOZ_UNICODE */
/*
***************************************************************************
** The file descriptor.
** This is the primary structure to represent any active open socket,
** whether it be a normal file or a network connection. Such objects
** are stackable (or layerable). Each layer may have its own set of
** method pointers and context private to that layer. All each layer
** knows about its neighbors is how to get to their method table.
***************************************************************************
*/
struct PRFileDesc {
/* A destructor function for layer */
};
/*
***************************************************************************
** PRTransmitFileFlags
**
** Flags for PR_TransmitFile. Pass PR_TRANSMITFILE_CLOSE_SOCKET to
** PR_TransmitFile if the connection should be closed after the file
** is transmitted.
***************************************************************************
*/
typedef enum PRTransmitFileFlags {
* is transmitted. */
* is transmitted. */
/*
**************************************************************************
** Macros for PRNetAddr
**
** Address families: PR_AF_INET, PR_AF_INET6, PR_AF_LOCAL
** IP addresses: PR_INADDR_ANY, PR_INADDR_LOOPBACK, PR_INADDR_BROADCAST
**************************************************************************
*/
#ifdef WIN32
#else /* WIN32 */
#endif /* WIN32 */
/*
** Define PR_AF_INET6 in prcpucfg.h with the same
** value as AF_INET6 on platforms with IPv6 support.
** Otherwise define it here.
*/
#ifndef PR_AF_INET6
#endif
#ifndef PR_AF_UNSPEC
#define PR_AF_UNSPEC 0
#endif
/*
**************************************************************************
** A network address
**
** Only Internet Protocol (IPv4 and IPv6) addresses are supported.
** The address family must always represent IPv4 (AF_INET, probably == 2)
** or IPv6 (AF_INET6).
**************************************************************************
*************************************************************************/
struct PRIPv6Addr {
union {
} _S6_un;
};
union PRNetAddr {
struct {
#ifdef XP_BEOS
#else
#endif
} raw;
struct {
#ifdef XP_BEOS
#else
#endif
} inet;
struct {
} ipv6;
#if defined(XP_UNIX) || defined(XP_OS2_EMX)
struct { /* Unix domain socket address */
#ifdef XP_OS2
/* bind fails if size is not 108. */
#else
#endif
} local;
#endif
};
/*
***************************************************************************
** PRSockOption
**
** The file descriptors can have predefined options set after they file
** descriptor is created to change their behavior. Only the options in
** the following enumeration are supported.
***************************************************************************
*/
typedef enum PRSockOption
{
} PRSockOption;
typedef struct PRLinger {
} PRLinger;
typedef struct PRMcastRequest {
typedef struct PRSocketOptionData
{
union
{
} value;
/*
***************************************************************************
** PRIOVec
**
** The I/O vector is used by the write vector method to describe the areas
** that are affected by the ouput operation.
***************************************************************************
*/
typedef struct PRIOVec {
char *iov_base;
int iov_len;
} PRIOVec;
/*
***************************************************************************
** Discover what type of socket is being described by the file descriptor.
***************************************************************************
*/
typedef enum PRDescType
{
} PRDescType;
typedef enum PRSeekWhence {
PR_SEEK_SET = 0,
} PRSeekWhence;
/*
***************************************************************************
** PRIOMethods
**
** The I/O methods table provides procedural access to the functions of
** the file descriptor. It is the responsibility of a layer implementor
** to provide suitable functions at every entry point. If a layer provides
** no functionality, it should call the next lower(higher) function of the
** same name (e.g., return fd->lower->method->close(fd->lower));
**
** Not all functions are implemented for all types of files. In cases where
** that is true, the function will return a error indication with an error
** code of PR_INVALID_METHOD_ERROR.
***************************************************************************
*/
struct PRIOMethods {
/* Get current setting of specified option */
/* Set value of specified option */
/* Continue a nonblocking connect */
};
/*
**************************************************************************
* FUNCTION: PR_GetSpecialFD
* DESCRIPTION: Get the file descriptor that represents the standard input,
* output, or error stream.
* INPUTS:
* PRSpecialFD id
* A value indicating the type of stream desired:
* PR_StandardInput: standard input
* PR_StandardOuput: standard output
* PR_StandardError: standard error
* OUTPUTS: none
* RETURNS: PRFileDesc *
* If the argument is valid, PR_GetSpecialFD returns a file descriptor
* that represents the corresponding standard I/O stream. Otherwise,
* PR_GetSpecialFD returns NULL and sets error PR_INVALID_ARGUMENT_ERROR.
**************************************************************************
*/
typedef enum PRSpecialFD
{
} PRSpecialFD;
/*
**************************************************************************
* Layering file descriptors
*
* File descriptors may be layered. Each layer has it's own identity.
* Identities are allocated by the runtime and are to be associated
* (by the layer implementor) with all layers that are of that type.
* It is then possible to scan the chain of layers and find a layer
* that one recongizes and therefore predict that it will implement
* a desired protocol.
*
* There are three well-known identities:
* PR_INVALID_IO_LAYER => an invalid layer identity, for error return
* PR_TOP_IO_LAYER => the identity of the top of the stack
* PR_NSPR_IO_LAYER => the identity used by NSPR proper
* PR_TOP_IO_LAYER may be used as a shorthand for identifying the topmost
* layer of an existing stack. Ie., the following two constructs are
* equivalent.
*
* rv = PR_PushIOLayer(stack, PR_TOP_IO_LAYER, my_layer);
* rv = PR_PushIOLayer(stack, PR_GetLayersIdentity(stack), my_layer)
*
* A string may be associated with the creation of the identity. It
* will be copied by the runtime. If queried the runtime will return
* a reference to that copied string (not yet another copy). There
* is no facility for deleting an identity.
**************************************************************************
*/
/*
**************************************************************************
* PR_GetDefaultIOMethods: Accessing the default methods table.
* You may get a pointer to the default methods table by calling this function.
* You may then select any elements from that table with which to build your
* layer's methods table. You may NOT modify the table directly.
**************************************************************************
*/
/*
**************************************************************************
* Creating a layer
*
* A new layer may be allocated by calling PR_CreateIOLayerStub(). The
* file descriptor returned will contain the pointer to the methods table
* provided. The runtime will not modify the table nor test its correctness.
**************************************************************************
*/
/*
**************************************************************************
* Creating a layer
*
* A new stack may be created by calling PR_CreateIOLayer(). The
* file descriptor returned will point to the top of the stack, which has
* the layer 'fd' as the topmost layer.
*
* NOTE: This function creates a new style stack, which has a fixed, dummy
* header. The old style stack, created by a call to PR_PushIOLayer,
* results in modifying contents of the top layer of the stack, when
* pushing and popping layers of the stack.
**************************************************************************
*/
/*
**************************************************************************
* Pushing a layer
*
* A file descriptor (perhaps allocated using PR_CreateIOLayerStub()) may
* be pushed into an existing stack of file descriptors at any point the
* caller deems appropriate. The new layer will be inserted into the stack
* just above the layer with the indicated identity.
*
* Note: Even if the identity parameter indicates the top-most layer of
* the stack, the value of the file descriptor describing the original
* stack will not change.
**************************************************************************
*/
/*
**************************************************************************
* Popping a layer
*
* A layer may be popped from a stack by indicating the identity of the
* layer to be removed. If found, a pointer to the removed object will
* be returned to the caller. The object then becomes the responsibility
* of the caller.
*
* Note: Even if the identity indicates the top layer of the stack, the
* reference returned will not be the file descriptor for the stack and
* that file descriptor will remain valid.
**************************************************************************
*/
/*
**************************************************************************
* FUNCTION: PR_Open
* DESCRIPTION: Open a file for reading, writing, or both.
* INPUTS:
* const char *name
* The path name of the file to be opened
* PRIntn flags
* The file status flags.
* It is a bitwise OR of the following bit flags (only one of
* the first three flags below may be used):
* PR_RDONLY Open for reading only.
* PR_WRONLY Open for writing only.
* PR_RDWR Open for reading and writing.
* PR_CREATE_FILE If the file does not exist, the file is created
* If the file exists, this flag has no effect.
* PR_SYNC If set, each write will wait for both the file data
* and file status to be physically updated.
* PR_APPEND The file pointer is set to the end of
* the file prior to each write.
* PR_TRUNCATE If the file exists, its length is truncated to 0.
* PR_EXCL With PR_CREATE_FILE, if the file does not exist,
* the file is created. If the file already
* exists, no action and NULL is returned
*
* PRIntn mode
* The access permission bits of the file mode, if the file is
* created when PR_CREATE_FILE is on.
* OUTPUTS: None
* RETURNS: PRFileDesc *
* If the file is successfully opened,
* returns a pointer to the PRFileDesc
* created for the newly opened file.
* Returns a NULL pointer if the open
* failed.
* SIDE EFFECTS:
* RESTRICTIONS:
* MEMORY:
* The return value, if not NULL, points to a dynamically allocated
* PRFileDesc object.
* ALGORITHM:
**************************************************************************
*/
/* Open flags */
/*
** File modes ....
**
** CAVEAT: 'mode' is currently only applicable on UNIX platforms.
** The 'mode' argument may be ignored by PR_Open on other platforms.
**
** 00400 Read by owner.
** 00200 Write by owner.
** 00100 Execute (search if a directory) by owner.
** 00040 Read by group.
** 00020 Write by group.
** 00010 Execute by group.
** 00004 Read by others.
** 00002 Write by others
** 00001 Execute by others.
**
*/
/*
**************************************************************************
* FUNCTION: PR_OpenFile
* DESCRIPTION:
* Open a file for reading, writing, or both.
* PR_OpenFile has the same prototype as PR_Open but implements
* the specified file mode where possible.
**************************************************************************
*/
/* File mode bits */
#ifdef MOZ_UNICODE
/*
* EXPERIMENTAL: This function may be removed in a future release.
*/
#endif /* MOZ_UNICODE */
/*
**************************************************************************
* FUNCTION: PR_Close
* DESCRIPTION:
* Close a file or socket.
* INPUTS:
* PRFileDesc *fd
* a pointer to a PRFileDesc.
* OUTPUTS:
* None.
* RETURN:
* PRStatus
* SIDE EFFECTS:
* RESTRICTIONS:
* None.
* MEMORY:
* The dynamic memory pointed to by the argument fd is freed.
**************************************************************************
*/
/*
**************************************************************************
* FUNCTION: PR_Read
* DESCRIPTION:
* Read bytes from a file or socket.
* The operation will block until either an end of stream indication is
* encountered, some positive number of bytes are transferred, or there
* is an error. No more than 'amount' bytes will be transferred.
* INPUTS:
* PRFileDesc *fd
* pointer to the PRFileDesc object for the file or socket
* void *buf
* pointer to a buffer to hold the data read in.
* PRInt32 amount
* the size of 'buf' (in bytes)
* OUTPUTS:
* RETURN:
* PRInt32
* a positive number indicates the number of bytes actually read in.
* 0 means end of file is reached or the network connection is closed.
* -1 indicates a failure. The reason for the failure is obtained
* by calling PR_GetError().
* SIDE EFFECTS:
* data is written into the buffer pointed to by 'buf'.
* RESTRICTIONS:
* None.
* MEMORY:
* N/A
* ALGORITHM:
* N/A
**************************************************************************
*/
/*
***************************************************************************
* FUNCTION: PR_Write
* DESCRIPTION:
* Write a specified number of bytes to a file or socket. The thread
* invoking this function blocks until all the data is written.
* INPUTS:
* PRFileDesc *fd
* pointer to a PRFileDesc object that refers to a file or socket
* const void *buf
* pointer to the buffer holding the data
* PRInt32 amount
* amount of data in bytes to be written from the buffer
* OUTPUTS:
* None.
* RETURN: PRInt32
* A positive number indicates the number of bytes successfully written.
* A -1 is an indication that the operation failed. The reason
* for the failure is obtained by calling PR_GetError().
***************************************************************************
*/
/*
***************************************************************************
* FUNCTION: PR_Writev
* DESCRIPTION:
* Write data to a socket. The data is organized in a PRIOVec array. The
* operation will block until all the data is written or the operation
* fails.
* INPUTS:
* PRFileDesc *fd
* Pointer that points to a PRFileDesc object for a socket.
* const PRIOVec *iov
* An array of PRIOVec. PRIOVec is a struct with the following
* two fields:
* char *iov_base;
* int iov_len;
* PRInt32 iov_size
* Number of elements in the iov array. The value of this
* argument must not be greater than PR_MAX_IOVECTOR_SIZE.
* If it is, the method will fail (PR_BUFFER_OVERFLOW_ERROR).
* PRIntervalTime timeout
* Time limit for completion of the entire write operation.
* OUTPUTS:
* None
* RETURN:
* A positive number indicates the number of bytes successfully written.
* A -1 is an indication that the operation failed. The reason
* for the failure is obtained by calling PR_GetError().
***************************************************************************
*/
/*
***************************************************************************
* FUNCTION: PR_Delete
* DESCRIPTION:
* Delete a file from the filesystem. The operation may fail if the
* file is open.
* INPUTS:
* const char *name
* Path name of the file to be deleted.
* OUTPUTS:
* None.
* RETURN: PRStatus
* The function returns PR_SUCCESS if the file is successfully
* deleted, otherwise it returns PR_FAILURE.
***************************************************************************
*/
/**************************************************************************/
typedef enum PRFileType
{
} PRFileType;
struct PRFileInfo {
};
struct PRFileInfo64 {
};
/****************************************************************************
* FUNCTION: PR_GetFileInfo, PR_GetFileInfo64
* DESCRIPTION:
* Get the information about the file with the given path name. This is
* applicable only to NSFileDesc describing 'file' types (see
* INPUTS:
* const char *fn
* path name of the file
* OUTPUTS:
* PRFileInfo *info
* Information about the given file is written into the file
* information object pointer to by 'info'.
* RETURN: PRStatus
* PR_GetFileInfo returns PR_SUCCESS if file information is successfully
* obtained, otherwise it returns PR_FAILURE.
***************************************************************************
*/
#ifdef MOZ_UNICODE
/*
* EXPERIMENTAL: This function may be removed in a future release.
*/
#endif /* MOZ_UNICODE */
/*
**************************************************************************
* FUNCTION: PR_GetOpenFileInfo, PR_GetOpenFileInfo64
* DESCRIPTION:
* Get information about an open file referred to by the
* given PRFileDesc object.
* INPUTS:
* const PRFileDesc *fd
* A reference to a valid, open file.
* OUTPUTS:
* Same as PR_GetFileInfo, PR_GetFileInfo64
* RETURN: PRStatus
* PR_GetFileInfo returns PR_SUCCESS if file information is successfully
* obtained, otherwise it returns PR_FAILURE.
***************************************************************************
*/
/*
**************************************************************************
* FUNCTION: PR_Rename
* DESCRIPTION:
* Rename a file from the old name 'from' to the new name 'to'.
* INPUTS:
* const char *from
* The old name of the file to be renamed.
* const char *to
* The new name of the file.
* OUTPUTS:
* None.
* RETURN: PRStatus
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_Access
* DESCRIPTION:
* Determine accessibility of a file.
* INPUTS:
* const char *name
* path name of the file
* PRAccessHow how
* specifies which access permission to check for.
* It can be one of the following values:
* PR_ACCESS_READ_OK Test for read permission
* PR_ACCESS_WRITE_OK Test for write permission
* PR_ACCESS_EXISTS Check existence of file
* OUTPUTS:
* None.
* RETURN: PRStatus
* PR_SUCCESS is returned if the requested access is permitted.
* Otherwise, PR_FAILURE is returned. Additional information
* regarding the reason for the failure may be retrieved from
* PR_GetError().
*************************************************************************
*/
typedef enum PRAccessHow {
} PRAccessHow;
/*
*************************************************************************
* FUNCTION: PR_Seek, PR_Seek64
* DESCRIPTION:
* Moves read-write file offset
* INPUTS:
* PRFileDesc *fd
* Pointer to a PRFileDesc object.
* PROffset32, PROffset64 offset
* Specifies a value, in bytes, that is used in conjunction
* with the 'whence' parameter to set the file pointer. A
* negative value causes seeking in the reverse direction.
* PRSeekWhence whence
* Specifies how to interpret the 'offset' parameter in setting
* the file pointer associated with the 'fd' parameter.
* Values for the 'whence' parameter are:
* PR_SEEK_SET Sets the file pointer to the value of the
* 'offset' parameter
* PR_SEEK_CUR Sets the file pointer to its current location
* plus the value of the offset parameter.
* PR_SEEK_END Sets the file pointer to the size of the
* file plus the value of the offset parameter.
* OUTPUTS:
* None.
* RETURN: PROffset32, PROffset64
* Upon successful completion, the resulting pointer location,
* measured in bytes from the beginning of the file, is returned.
* If the PR_Seek() function fails, the file offset remains
* unchanged, and the returned value is -1. The error code can
* then be retrieved via PR_GetError().
*************************************************************************
*/
/*
************************************************************************
* FUNCTION: PR_Available
* DESCRIPTION:
* Determine the amount of data in bytes available for reading
* in the given file or socket.
* INPUTS:
* PRFileDesc *fd
* Pointer to a PRFileDesc object that refers to a file or
* socket.
* OUTPUTS:
* None
* RETURN: PRInt32, PRInt64
* Upon successful completion, PR_Available returns the number of
* bytes beyond the current read pointer that is available for
* reading. Otherwise, it returns a -1 and the reason for the
* failure can be retrieved via PR_GetError().
************************************************************************
*/
/*
************************************************************************
* FUNCTION: PR_Sync
* DESCRIPTION:
* Sync any buffered data for a fd to its backing device (disk).
* INPUTS:
* PRFileDesc *fd
* Pointer to a PRFileDesc object that refers to a file or
* socket
* OUTPUTS:
* None
* RETURN: PRStatus
* PR_SUCCESS is returned if the requested access is permitted.
* Otherwise, PR_FAILURE is returned.
************************************************************************
*/
/************************************************************************/
struct PRDirEntry {
};
#ifdef MOZ_UNICODE
struct PRDirEntryUTF16 {
* directory name */
};
#endif /* MOZ_UNICODE */
#if !defined(NO_NSPR_10_SUPPORT)
#endif
/*
*************************************************************************
* FUNCTION: PR_OpenDir
* DESCRIPTION:
* Open the directory by the given name
* INPUTS:
* const char *name
* path name of the directory to be opened
* OUTPUTS:
* None
* RETURN: PRDir *
* If the directory is sucessfully opened, a PRDir object is
* dynamically allocated and a pointer to it is returned.
* If the directory cannot be opened, a NULL pointer is returned.
* MEMORY:
* Upon successful completion, the return value points to
* dynamically allocated memory.
*************************************************************************
*/
#ifdef MOZ_UNICODE
/*
* EXPERIMENTAL: This function may be removed in a future release.
*/
#endif /* MOZ_UNICODE */
/*
*************************************************************************
* FUNCTION: PR_ReadDir
* DESCRIPTION:
* INPUTS:
* PRDir *dir
* pointer to a PRDir object that designates an open directory
* PRDirFlags flags
* PR_SKIP_NONE Do not skip any files
* PR_SKIP_DOT Skip the directory entry "." that
* represents the current directory
* PR_SKIP_DOT_DOT Skip the directory entry ".." that
* represents the parent directory.
* PR_SKIP_BOTH Skip both '.' and '..'
* PR_SKIP_HIDDEN Skip hidden files
* OUTPUTS:
* RETURN: PRDirEntry*
* Returns a pointer to the next entry in the directory. Returns
* a NULL pointer upon reaching the end of the directory or when an
* error occurs. The actual reason can be retrieved via PR_GetError().
*************************************************************************
*/
typedef enum PRDirFlags {
} PRDirFlags;
#ifdef MOZ_UNICODE
/*
* EXPERIMENTAL: This function may be removed in a future release.
*/
#endif /* MOZ_UNICODE */
/*
*************************************************************************
* FUNCTION: PR_CloseDir
* DESCRIPTION:
* Close the specified directory.
* INPUTS:
* PRDir *dir
* The directory to be closed.
* OUTPUTS:
* None
* RETURN: PRStatus
* If successful, will return a status of PR_SUCCESS. Otherwise
* a value of PR_FAILURE. The reason for the failure may be re-
* trieved using PR_GetError().
*************************************************************************
*/
#ifdef MOZ_UNICODE
/*
* EXPERIMENTAL: This function may be removed in a future release.
*/
#endif /* MOZ_UNICODE */
/*
*************************************************************************
* FUNCTION: PR_MkDir
* DESCRIPTION:
* Create a new directory with the given name and access mode.
* INPUTS:
* const char *name
* The name of the directory to be created. All the path components
* up to but not including the leaf component must already exist.
* PRIntn mode
* See 'mode' definiton in PR_Open().
* OUTPUTS:
* None
* RETURN: PRStatus
* If successful, will return a status of PR_SUCCESS. Otherwise
* a value of PR_FAILURE. The reason for the failure may be re-
* trieved using PR_GetError().
*************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_MakeDir
* DESCRIPTION:
* Create a new directory with the given name and access mode.
* PR_MakeDir has the same prototype as PR_MkDir but implements
* the specified access mode where possible.
*************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_RmDir
* DESCRIPTION:
* Remove a directory by the given name.
* INPUTS:
* const char *name
* The name of the directory to be removed. All the path components
* must already exist. Only the leaf component will be removed.
* OUTPUTS:
* None
* RETURN: PRStatus
* If successful, will return a status of PR_SUCCESS. Otherwise
* a value of PR_FAILURE. The reason for the failure may be re-
* trieved using PR_GetError().
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_NewUDPSocket
* DESCRIPTION:
* Create a new UDP socket.
* INPUTS:
* None
* OUTPUTS:
* None
* RETURN: PRFileDesc*
* Upon successful completion, PR_NewUDPSocket returns a pointer
* to the PRFileDesc created for the newly opened UDP socket.
* Returns a NULL pointer if the creation of a new UDP socket failed.
*
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_NewTCPSocket
* DESCRIPTION:
* Create a new TCP socket.
* INPUTS:
* None
* OUTPUTS:
* None
* RETURN: PRFileDesc*
* Upon successful completion, PR_NewTCPSocket returns a pointer
* to the PRFileDesc created for the newly opened TCP socket.
* Returns a NULL pointer if the creation of a new TCP socket failed.
*
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_OpenUDPSocket
* DESCRIPTION:
* Create a new UDP socket of the specified address family.
* INPUTS:
* PRIntn af
* Address family
* OUTPUTS:
* None
* RETURN: PRFileDesc*
* Upon successful completion, PR_OpenUDPSocket returns a pointer
* to the PRFileDesc created for the newly opened UDP socket.
* Returns a NULL pointer if the creation of a new UDP socket failed.
*
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_OpenTCPSocket
* DESCRIPTION:
* Create a new TCP socket of the specified address family.
* INPUTS:
* PRIntn af
* Address family
* OUTPUTS:
* None
* RETURN: PRFileDesc*
* Upon successful completion, PR_NewTCPSocket returns a pointer
* to the PRFileDesc created for the newly opened TCP socket.
* Returns a NULL pointer if the creation of a new TCP socket failed.
*
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_Connect
* DESCRIPTION:
* Initiate a connection on a socket.
* INPUTS:
* PRFileDesc *fd
* Points to a PRFileDesc object representing a socket
* PRNetAddr *addr
* Specifies the address of the socket in its own communication
* space.
* PRIntervalTime timeout
* Time limit for completion of the connect operation.
* OUTPUTS:
* None
* RETURN: PRStatus
* Upon successful completion of connection initiation, PR_Connect
* returns PR_SUCCESS. Otherwise, it returns PR_FAILURE. Further
* failure information can be obtained by calling PR_GetError().
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_ConnectContinue
* DESCRIPTION:
* Continue a nonblocking connect. After a nonblocking connect
* is initiated with PR_Connect() (which fails with
* PR_IN_PROGRESS_ERROR), one should call PR_Poll() on the socket,
* with the in_flags PR_POLL_WRITE | PR_POLL_EXCEPT. When
* PR_Poll() returns, one calls PR_ConnectContinue() on the
* socket to determine whether the nonblocking connect has
* completed or is still in progress. Repeat the PR_Poll(),
* PR_ConnectContinue() sequence until the nonblocking connect
* has completed.
* INPUTS:
* PRFileDesc *fd
* the file descriptor representing a socket
* PRInt16 out_flags
* the out_flags field of the poll descriptor returned by
* PR_Poll()
* RETURN: PRStatus
* If the nonblocking connect has successfully completed,
* PR_ConnectContinue returns PR_SUCCESS. If PR_ConnectContinue()
* returns PR_FAILURE, call PR_GetError():
* - PR_IN_PROGRESS_ERROR: the nonblocking connect is still in
* progress and has not completed yet. The caller should poll
* on the file descriptor for the in_flags
* PR_POLL_WRITE|PR_POLL_EXCEPT and retry PR_ConnectContinue
* later when PR_Poll() returns.
* - Other errors: the nonblocking connect has failed with this
* error code.
*/
/*
*************************************************************************
* THIS FUNCTION IS DEPRECATED. USE PR_ConnectContinue INSTEAD.
*
* FUNCTION: PR_GetConnectStatus
* DESCRIPTION:
* Get the completion status of a nonblocking connect. After
* a nonblocking connect is initiated with PR_Connect() (which
* fails with PR_IN_PROGRESS_ERROR), one should call PR_Poll()
* on the socket, with the in_flags PR_POLL_WRITE | PR_POLL_EXCEPT.
* When PR_Poll() returns, one calls PR_GetConnectStatus on the
* PRPollDesc structure to determine whether the nonblocking
* connect has succeeded or failed.
* INPUTS:
* const PRPollDesc *pd
* Pointer to a PRPollDesc whose fd member is the socket,
* and in_flags must contain PR_POLL_WRITE and PR_POLL_EXCEPT.
* PR_Poll() should have been called and set the out_flags.
* RETURN: PRStatus
* If the nonblocking connect has successfully completed,
* PR_GetConnectStatus returns PR_SUCCESS. If PR_GetConnectStatus()
* returns PR_FAILURE, call PR_GetError():
* - PR_IN_PROGRESS_ERROR: the nonblocking connect is still in
* progress and has not completed yet.
* - Other errors: the nonblocking connect has failed with this
* error code.
*/
/*
*************************************************************************
* FUNCTION: PR_Accept
* DESCRIPTION:
* Accept a connection on a socket.
* INPUTS:
* PRFileDesc *fd
* Points to a PRFileDesc object representing the rendezvous socket
* on which the caller is willing to accept new connections.
* PRIntervalTime timeout
* Time limit for completion of the accept operation.
* OUTPUTS:
* PRNetAddr *addr
* Returns the address of the connecting entity in its own
* communication space. It may be NULL.
* RETURN: PRFileDesc*
* Upon successful acceptance of a connection, PR_Accept
* returns a valid file descriptor. Otherwise, it returns NULL.
* Further failure information can be obtained by calling PR_GetError().
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_Bind
* DESCRIPTION:
* Bind an address to a socket.
* INPUTS:
* PRFileDesc *fd
* Points to a PRFileDesc object representing a socket.
* PRNetAddr *addr
* Specifies the address to which the socket will be bound.
* OUTPUTS:
* None
* RETURN: PRStatus
* Upon successful binding of an address to a socket, PR_Bind
* returns PR_SUCCESS. Otherwise, it returns PR_FAILURE. Further
* failure information can be obtained by calling PR_GetError().
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_Listen
* DESCRIPTION:
* Listen for connections on a socket.
* INPUTS:
* PRFileDesc *fd
* Points to a PRFileDesc object representing a socket that will be
* used to listen for new connections.
* PRIntn backlog
* Specifies the maximum length of the queue of pending connections.
* OUTPUTS:
* None
* RETURN: PRStatus
* Upon successful completion of listen request, PR_Listen
* returns PR_SUCCESS. Otherwise, it returns PR_FAILURE. Further
* failure information can be obtained by calling PR_GetError().
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_Shutdown
* DESCRIPTION:
* Shut down part of a full-duplex connection on a socket.
* INPUTS:
* PRFileDesc *fd
* Points to a PRFileDesc object representing a connected socket.
* PRIntn how
* Specifies the kind of disallowed operations on the socket.
* PR_SHUTDOWN_RCV - Further receives will be disallowed
* PR_SHUTDOWN_SEND - Further sends will be disallowed
* PR_SHUTDOWN_BOTH - Further sends and receives will be disallowed
* OUTPUTS:
* None
* RETURN: PRStatus
* Upon successful completion of shutdown request, PR_Shutdown
* returns PR_SUCCESS. Otherwise, it returns PR_FAILURE. Further
* failure information can be obtained by calling PR_GetError().
**************************************************************************
*/
typedef enum PRShutdownHow
{
/*
*************************************************************************
* FUNCTION: PR_Recv
* DESCRIPTION:
* Receive a specified number of bytes from a connected socket.
* The operation will block until some positive number of bytes are
* transferred, a time out has occurred, or there is an error.
* No more than 'amount' bytes will be transferred.
* INPUTS:
* PRFileDesc *fd
* points to a PRFileDesc object representing a socket.
* void *buf
* pointer to a buffer to hold the data received.
* PRInt32 amount
* the size of 'buf' (in bytes)
* PRIntn flags
* must be zero or PR_MSG_PEEK.
* PRIntervalTime timeout
* Time limit for completion of the receive operation.
* OUTPUTS:
* None
* RETURN: PRInt32
* a positive number indicates the number of bytes actually received.
* 0 means the network connection is closed.
* -1 indicates a failure. The reason for the failure is obtained
* by calling PR_GetError().
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_Send
* DESCRIPTION:
* Send a specified number of bytes from a connected socket.
* The operation will block until all bytes are
* processed, a time out has occurred, or there is an error.
* INPUTS:
* PRFileDesc *fd
* points to a PRFileDesc object representing a socket.
* void *buf
* pointer to a buffer from where the data is sent.
* PRInt32 amount
* the size of 'buf' (in bytes)
* PRIntn flags
* (OBSOLETE - must always be zero)
* PRIntervalTime timeout
* Time limit for completion of the send operation.
* OUTPUTS:
* None
* RETURN: PRInt32
* A positive number indicates the number of bytes successfully processed.
* This number must always equal 'amount'. A -1 is an indication that the
* operation failed. The reason for the failure is obtained by calling
* PR_GetError().
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_RecvFrom
* DESCRIPTION:
* Receive up to a specified number of bytes from socket which may
* or may not be connected.
* The operation will block until one or more bytes are
* transferred, a time out has occurred, or there is an error.
* No more than 'amount' bytes will be transferred.
* INPUTS:
* PRFileDesc *fd
* points to a PRFileDesc object representing a socket.
* void *buf
* pointer to a buffer to hold the data received.
* PRInt32 amount
* the size of 'buf' (in bytes)
* PRIntn flags
* (OBSOLETE - must always be zero)
* PRNetAddr *addr
* Specifies the address of the sending peer. It may be NULL.
* PRIntervalTime timeout
* Time limit for completion of the receive operation.
* OUTPUTS:
* None
* RETURN: PRInt32
* a positive number indicates the number of bytes actually received.
* 0 means the network connection is closed.
* -1 indicates a failure. The reason for the failure is obtained
* by calling PR_GetError().
**************************************************************************
*/
/*
*************************************************************************
* FUNCTION: PR_SendTo
* DESCRIPTION:
* Send a specified number of bytes from an unconnected socket.
* The operation will block until all bytes are
* sent, a time out has occurred, or there is an error.
* INPUTS:
* PRFileDesc *fd
* points to a PRFileDesc object representing an unconnected socket.
* void *buf
* pointer to a buffer from where the data is sent.
* PRInt32 amount
* the size of 'buf' (in bytes)
* PRIntn flags
* (OBSOLETE - must always be zero)
* PRNetAddr *addr
* Specifies the address of the peer.
.* PRIntervalTime timeout
* Time limit for completion of the send operation.
* OUTPUTS:
* None
* RETURN: PRInt32
* A positive number indicates the number of bytes successfully sent.
* -1 indicates a failure. The reason for the failure is obtained
* by calling PR_GetError().
**************************************************************************
*/
/*
*************************************************************************
** FUNCTION: PR_TransmitFile
** DESCRIPTION:
** Transmitfile sends a complete file (sourceFile) across a socket
** (networkSocket). If headers is non-NULL, the headers will be sent across
** the socket prior to sending the file.
**
** Optionally, the PR_TRANSMITFILE_CLOSE_SOCKET flag may be passed to
** transmitfile. This flag specifies that transmitfile should close the
** socket after sending the data.
**
** INPUTS:
** PRFileDesc *networkSocket
** The socket to send data over
** PRFileDesc *sourceFile
** The file to send
** const void *headers
** A pointer to headers to be sent before sending data
** PRInt32 hlen
** length of header buffers in bytes.
** PRTransmitFileFlags flags
** If the flags indicate that the connection should be closed,
** it will be done immediately after transferring the file, unless
** the operation is unsuccessful.
.* PRIntervalTime timeout
* Time limit for completion of the transmit operation.
**
** RETURNS:
** Returns the number of bytes written or -1 if the operation failed.
** If an error occurs while sending the file, the PR_TRANSMITFILE_CLOSE_
** SOCKET flag is ignored. The reason for the failure is obtained
** by calling PR_GetError().
**************************************************************************
*/
/*
*************************************************************************
** FUNCTION: PR_SendFile
** DESCRIPTION:
** PR_SendFile sends data from a file (sendData->fd) across a socket
** before and after the file, respectively. The file offset, number of bytes
** of file data to send, the header and trailer buffers are specified in the
** sendData argument.
**
** Optionally, if the PR_TRANSMITFILE_CLOSE_SOCKET flag is passed, the
** socket is closed after successfully sending the data.
**
** INPUTS:
** PRFileDesc *networkSocket
** The socket to send data over
** PRSendFileData *sendData
** Contains the FD, file offset and length, header and trailer
** buffer specifications.
** PRTransmitFileFlags flags
** If the flags indicate that the connection should be closed,
** it will be done immediately after transferring the file, unless
** the operation is unsuccessful.
.* PRIntervalTime timeout
* Time limit for completion of the send operation.
**
** RETURNS:
** Returns the number of bytes written or -1 if the operation failed.
** If an error occurs while sending the file, the PR_TRANSMITFILE_CLOSE_
** SOCKET flag is ignored. The reason for the failure is obtained
** by calling PR_GetError().
**************************************************************************
*/
struct PRSendFileData {
/* if 0, send data from file_offset to */
/* end-of-file. */
};
/*
*************************************************************************
** FUNCTION: PR_AcceptRead
** DESCRIPTION:
** AcceptRead accepts a new connection, returns the newly created
** socket's descriptor and also returns the connecting peer's address.
** AcceptRead, as its name suggests, also receives the first block of data
** sent by the peer.
**
** INPUTS:
** PRFileDesc *listenSock
** A socket descriptor that has been called with the PR_Listen()
** function, also known as the rendezvous socket.
** void *buf
** A pointer to a buffer to receive data sent by the client. This
** buffer must be large enough to receive <amount> bytes of data
** and two PRNetAddr structures, plus an extra 32 bytes. See:
** PR_ACCEPT_READ_BUF_OVERHEAD.
** PRInt32 amount
** The number of bytes of client data to receive. Does not include
** the size of the PRNetAddr structures. If 0, no data will be read
** from the client.
** PRIntervalTime timeout
** The timeout interval only applies to the read portion of the
** operation. PR_AcceptRead will block indefinitely until the
** connection is accepted; the read will timeout after the timeout
** interval elapses.
** OUTPUTS:
** PRFileDesc **acceptedSock
** The file descriptor for the newly connected socket. This parameter
** will only be valid if the function return does not indicate failure.
** PRNetAddr **peerAddr,
** The address of the remote socket. This parameter will only be
** valid if the function return does not indicate failure. The
** returned address is not guaranteed to be properly aligned.
**
** RETURNS:
** The number of bytes read from the client or -1 on failure. The reason
** for the failure is obtained by calling PR_GetError().
**************************************************************************
**/
/* define buffer overhead constant. Add this value to the user's
** data length when allocating a buffer to accept data.
** Example:
** #define USER_DATA_SIZE 10
** char buf[USER_DATA_SIZE + PR_ACCEPT_READ_BUF_OVERHEAD];
** bytesRead = PR_AcceptRead( s, fd, &a, &p, USER_DATA_SIZE, ...);
*/
/*
*************************************************************************
** FUNCTION: PR_NewTCPSocketPair
** DESCRIPTION:
** Create a new TCP socket pair. The returned descriptors can be used
** interchangeably; they are interconnected full-duplex descriptors: data
** written to one can be read from the other and vice-versa.
**
** INPUTS:
** None
** OUTPUTS:
** PRFileDesc *fds[2]
** The file descriptor pair for the newly created TCP sockets.
** RETURN: PRStatus
** Upon successful completion of TCP socket pair, PR_NewTCPSocketPair
** returns PR_SUCCESS. Otherwise, it returns PR_FAILURE. Further
** failure information can be obtained by calling PR_GetError().
** XXX can we implement this on windoze and mac?
**************************************************************************
**/
/*
*************************************************************************
** FUNCTION: PR_GetSockName
** DESCRIPTION:
** Get socket name. Return the network address for this socket.
**
** INPUTS:
** PRFileDesc *fd
** Points to a PRFileDesc object representing the socket.
** OUTPUTS:
** PRNetAddr *addr
** Returns the address of the socket in its own communication space.
** RETURN: PRStatus
** Upon successful completion, PR_GetSockName returns PR_SUCCESS.
** Otherwise, it returns PR_FAILURE. Further failure information can
** be obtained by calling PR_GetError().
**************************************************************************
**/
/*
*************************************************************************
** FUNCTION: PR_GetPeerName
** DESCRIPTION:
** Get name of the connected peer. Return the network address for the
** connected peer socket.
**
** INPUTS:
** PRFileDesc *fd
** Points to a PRFileDesc object representing the connected peer.
** OUTPUTS:
** PRNetAddr *addr
** Returns the address of the connected peer in its own communication
** space.
** RETURN: PRStatus
** Upon successful completion, PR_GetPeerName returns PR_SUCCESS.
** Otherwise, it returns PR_FAILURE. Further failure information can
** be obtained by calling PR_GetError().
**************************************************************************
**/
/*
*********************************************************************
*
* File descriptor inheritance
*
*********************************************************************
*/
/*
************************************************************************
* FUNCTION: PR_SetFDInheritable
* DESCRIPTION:
* Set the inheritance attribute of a file descriptor.
*
* INPUTS:
* PRFileDesc *fd
* Points to a PRFileDesc object.
* PRBool inheritable
* If PR_TRUE, the file descriptor fd is set to be inheritable
* by a child process. If PR_FALSE, the file descriptor is set
* to be not inheritable by a child process.
* RETURN: PRStatus
* Upon successful completion, PR_SetFDInheritable returns PR_SUCCESS.
* Otherwise, it returns PR_FAILURE. Further failure information can
* be obtained by calling PR_GetError().
*************************************************************************
*/
PRFileDesc *fd,
/*
************************************************************************
* FUNCTION: PR_GetInheritedFD
* DESCRIPTION:
* Get an inherited file descriptor with the specified name.
*
* INPUTS:
* const char *name
* The name of the inherited file descriptor.
* RETURN: PRFileDesc *
* Upon successful completion, PR_GetInheritedFD returns the
* inherited file descriptor with the specified name. Otherwise,
* it returns NULL. Further failure information can be obtained
* by calling PR_GetError().
*************************************************************************
*/
/*
*********************************************************************
*
* Memory-mapped files
*
*********************************************************************
*/
/*
* protection options for read and write accesses of a file mapping
*/
typedef enum PRFileMapProtect {
PRFileDesc *fd,
/*
* return the alignment (in bytes) of the offset argument to PR_MemMap
*/
* return value of PR_GetMemMapAlignment() */
/*
******************************************************************
*
* Interprocess communication
*
******************************************************************
*/
/*
* Creates an anonymous pipe and returns file descriptors for the
* read and write ends of the pipe.
*/
);
/************************************************************************/
/************** The following definitions are for poll ******************/
/************************************************************************/
struct PRPollDesc {
};
/*
** Bit values for PRPollDesc.in_flags or PRPollDesc.out_flags. Binary-or
** these together to produce the desired poll request.
*/
#if defined(_PR_POLL_BACKCOMPAT)
#include <poll.h>
#else /* _PR_POLL_BACKCOMPAT */
#endif /* _PR_POLL_BACKCOMPAT */
/*
*************************************************************************
** FUNCTION: PR_Poll
** DESCRIPTION:
**
** The call returns as soon as I/O is ready on one or more of the underlying
** socket objects. A count of the number of ready descriptors is
** returned unless a timeout occurs in which case zero is returned.
**
** PRPollDesc.fd should be set to a pointer to a PRFileDesc object
** representing a socket. This field can be set to NULL to indicate to
** PR_Poll that this PRFileDesc object should be ignored.
** PRPollDesc.in_flags should be set to the desired request
** this call PRPollDesc.out_flags will be set to indicate what kind of
** i/o can be performed on the respective descriptor. PR_Poll() uses the
** out_flags fields as scratch variables during the call. If PR_Poll()
** returns 0 or -1, the out_flags fields do not contain meaningful values
** and must not be used.
**
** INPUTS:
** PRPollDesc *pds A pointer to an array of PRPollDesc
**
** PRIntn npds The number of elements in the array
** If this argument is zero PR_Poll is
** equivalent to a PR_Sleep(timeout).
**
** PRIntervalTime timeout Amount of time the call will block waiting
** for I/O to become ready. If this time expires
** w/o any I/O becoming ready, the result will
** be zero.
**
** OUTPUTS: None
** RETURN:
** PRInt32 Number of PRPollDesc's with events or zero
** if the function timed out or -1 on failure.
** The reason for the failure is obtained by
** calling PR_GetError().
**************************************************************************
*/
/*
**************************************************************************
**
** Pollable events
**
** A pollable event is a special kind of file descriptor.
** The only I/O operation you can perform on a pollable event
** is to poll it with the PR_POLL_READ flag. You can't
** read from or write to a pollable event.
**
** The purpose of a pollable event is to combine event waiting
** with I/O waiting in a single PR_Poll call. Pollable events
** are implemented using a pipe or a pair of TCP sockets
** connected via the loopback address, therefore setting and
** waiting for pollable events are expensive operating system
** calls. Do not use pollable events for general thread
** synchronization. Use condition variables instead.
**
** A pollable event has two states: set and unset. Events
** are not queued, so there is no notion of an event count.
** A pollable event is either set or unset.
**
** A new pollable event is created by a PR_NewPollableEvent
** call and is initially in the unset state.
**
** PR_WaitForPollableEvent blocks the calling thread until
** the pollable event is set, and then it atomically unsets
** the pollable event before it returns.
**
** To set a pollable event, call PR_SetPollableEvent.
**
** One can call PR_Poll with the PR_POLL_READ flag on a pollable
** event. When the pollable event is set, PR_Poll returns with
** the PR_POLL_READ flag set in the out_flags.
**
** To close a pollable event, call PR_DestroyPollableEvent
** (not PR_Close).
**
**************************************************************************
*/
#endif /* prio_h___ */