📄 prmwait.h
字号:
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* * 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 http://www.mozilla.org/MPL/ * * 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 Netscape are * Copyright (C) 1998-2000 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL"), in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your * version of this file only under the terms of the GPL and not to * allow others to use your version of this file under the MPL, * indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient * may use your version of this file under either the MPL or the * GPL. */#if defined(_PRMWAIT_H)#else#define _PRMWAIT_H#include "prio.h"#include "prtypes.h"#include "prclist.h"PR_BEGIN_EXTERN_C/********************************************************************************//********************************************************************************//********************************************************************************//****************************** WARNING ****************************//********************************************************************************//**************************** This is work in progress. *************************//************************** Do not make any assumptions *************************//************************** about the stability of this *************************//************************** API or the underlying imple- ************************//************************** mentation. ************************//********************************************************************************//********************************************************************************//*** STRUCTURE: PRWaitGroup** DESCRIPTION:** The client may define several wait groups in order to semantically** tie a collection of file descriptors for a single purpose. This allows** easier dispatching of threads that returned with active file descriptors** from the wait function.*/typedef struct PRWaitGroup PRWaitGroup;/*** ENUMERATION: PRMWStatus** DESCRIPTION:** This enumeration is used to indicate the completion status of** a receive wait object. Generally stated, a positive value indicates** that the operation is not yet complete. A zero value indicates** success (similar to PR_SUCCESS) and any negative value is an** indication of failure. The reason for the failure can be retrieved** by calling PR_GetError().**** PR_MW_PENDING The operation is still pending. None of the other** fields of the object are currently valid.** PR_MW_SUCCESS The operation is complete and it was successful.** PR_MW_FAILURE The operation failed. The reason for the failure** can be retrieved by calling PR_GetError().** PR_MW_TIMEOUT The amount of time allowed for by the object's** 'timeout' field has expired w/o the operation** otherwise coming to closure.** PR_MW_INTERRUPT The operation was cancelled, either by the client** calling PR_CancelWaitFileDesc() or destroying the** entire wait group (PR_DestroyWaitGroup()).*/typedef enum PRMWStatus{ PR_MW_PENDING = 1, PR_MW_SUCCESS = 0, PR_MW_FAILURE = -1, PR_MW_TIMEOUT = -2, PR_MW_INTERRUPT = -3} PRMWStatus;/*** STRUCTURE: PRMemoryDescriptor** DESCRIPTION:** THis is a descriptor for an interval of memory. It contains a** pointer to the first byte of that memory and the length (in** bytes) of the interval.*/typedef struct PRMemoryDescriptor{ void *start; /* pointer to first byte of memory */ PRSize length; /* length (in bytes) of memory interval */} PRMemoryDescriptor;/*** STRUCTURE: PRMWaitClientData** DESCRIPTION:** An opague stucture for which a client MAY give provide a concrete** definition and associate with a receive descriptor. The NSPR runtime** does not manage this field. It is completely up to the client.*/typedef struct PRMWaitClientData PRMWaitClientData;/*** STRUCTURE: PRRecvWait** DESCRIPTION:** A receive wait object contains the file descriptor that is subject** to the wait and the amount of time (beginning epoch established** when the object is presented to the runtime) the the channel should** block before abandoning the process.**** The success of the wait operation will be noted in the object's** 'outcome' field. The fields are not valid when the NSPR runtime** is in possession of the object.**** The memory descriptor describes an interval of writable memory** in the caller's address space where data from an initial read** can be placed. The description may indicate a null interval.*/typedef struct PRRecvWait { PRCList internal; /* internal runtime linkages */ PRFileDesc *fd; /* file descriptor associated w/ object */ PRMWStatus outcome; /* outcome of the current/last operation */ PRIntervalTime timeout; /* time allowed for entire operation */ PRInt32 bytesRecv; /* number of bytes transferred into buffer */ PRMemoryDescriptor buffer; /* where to store first segment of input data */ PRMWaitClientData *client; /* pointer to arbitrary client defined data */} PRRecvWait;/*** STRUCTURE: PRMWaitEnumerator** DESCRIPTION:** An enumeration object is used to store the state of an existing** enumeration over a wait group. The opaque object must be allocated** by the client and the reference presented on each call to the** pseudo-stateless enumerator. The enumeration objects are sharable** only in serial fashion.*/typedef struct PRMWaitEnumerator PRMWaitEnumerator;/*** FUNCTION: PR_AddWaitFileDesc** DESCRIPTION:** This function will effectively add a file descriptor to the** list of those waiting for network receive. The new descriptor** will be semantically tied to the wait group specified.**** The ownership for the storage pointed to by 'desc' is temporarily** passed over the the NSPR runtime. It will be handed back by the** function PR_WaitRecvReady().**** INPUTS** group A reference to a PRWaitGroup or NULL. Wait groups are** created by calling PR_CreateWaitGroup() and are used** to semantically group various file descriptors by the** client's application.** desc A reference to a valid PRRecvWait. The object of the** reference must be preserved and not be modified** until its ownership is returned to the client.** RETURN** PRStatus An indication of success. If equal to PR_FAILUE details** of the failure are avaiable via PR_GetError().**** ERRORS** PR_INVALID_ARGUMENT_ERROR** Invalid 'group' identifier or duplicate 'desc' object.** PR_OUT_OF_MEMORY_ERROR** Insuffient memory for internal data structures.** PR_INVALID_STATE_ERROR** The group is being destroyed.*/NSPR_API(PRStatus) PR_AddWaitFileDesc(PRWaitGroup *group, PRRecvWait *desc);/*** FUNCTION: PR_WaitRecvReady** DESCRIPTION:** PR_WaitRecvReady will block the calling thread until one of the** file descriptors that have been added via PR_AddWaitFileDesc is** available for input I/O.** INPUT** group A pointer to a valid PRWaitGroup or NULL (the null** group. The function will block the caller until a** channel from the wait group becomes ready for receive** or there is some sort of error.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -