本文整理汇总了C++中PR_SecondsToInterval函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_SecondsToInterval函数的具体用法?C++ PR_SecondsToInterval怎么用?C++ PR_SecondsToInterval使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PR_SecondsToInterval函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConnectThread
static void ConnectThread( void *arg )
{
PRStatus rv;
PRFileDesc *clientSock;
PRNetAddr serverAddress;
clientSock = PR_NewTCPSocket();
PR_ASSERT(clientSock);
if ( resume ) {
if ( debug ) printf("pausing 3 seconds before connect\n");
PR_Sleep( PR_SecondsToInterval(3));
}
memset(&serverAddress, 0, sizeof(serverAddress));
rv = PR_InitializeNetAddr(PR_IpAddrLoopback, BASE_PORT, &serverAddress);
PR_ASSERT( PR_SUCCESS == rv );
rv = PR_Connect( clientSock,
&serverAddress,
PR_SecondsToInterval(1));
PR_ASSERT( PR_SUCCESS == rv );
/* that's all we do. ... Wait for the acceptread() to timeout */
while( state != AllDone )
PR_Sleep( PR_SecondsToInterval(1));
return;
} /* end ConnectThread() */
示例2: Alarms2
static PRIntervalTime Alarms2(PRUint32 loops)
{
PRStatus rv;
PRAlarm *alarm;
PRIntervalTime overhead, timein = PR_IntervalNow();
AlarmData ad;
PRIntervalTime duration = PR_SecondsToInterval(30);
PRLock *ml = PR_NewLock();
PRCondVar *cv = PR_NewCondVar(ml);
ad.ml = ml;
ad.cv = cv;
ad.rate = 1;
ad.times = loops;
ad.late = ad.times = 0;
ad.duration = duration;
ad.timein = PR_IntervalNow();
ad.period = PR_SecondsToInterval(1);
alarm = PR_CreateAlarm();
(void)PR_SetAlarm(
alarm, ad.period, ad.rate, AlarmFn2, &ad);
overhead = PR_IntervalNow() - timein;
PR_Lock(ml);
while ((PRIntervalTime)(PR_IntervalNow() - ad.timein) < duration)
PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT);
PR_Unlock(ml);
timein = PR_IntervalNow();
rv = PR_DestroyAlarm(alarm);
if (rv != PR_SUCCESS)
{
if (!debug_mode)
failed_already=1;
else
printf("***Destroying alarm status: FAIL\n");
}
PR_DestroyCondVar(cv);
PR_DestroyLock(ml);
overhead += (PR_IntervalNow() - timein);
return duration + overhead;
} /* Alarms2 */
示例3: Curl_nss_recv
/*
* If the read would block we return -1 and set 'wouldblock' to TRUE.
* Otherwise we return the amount of data read. Other errors should return -1
* and set 'wouldblock' to FALSE.
*/
ssize_t Curl_nss_recv(struct connectdata * conn, /* connection data */
int num, /* socketindex */
char *buf, /* store read data here */
size_t buffersize, /* max amount to read */
bool * wouldblock)
{
ssize_t nread;
struct SessionHandle *data = conn->data;
PRInt32 timeout;
if(data->set.timeout)
timeout = PR_SecondsToInterval((PRUint32)data->set.timeout);
else
timeout = PR_MillisecondsToInterval(DEFAULT_CONNECT_TIMEOUT);
nread = PR_Recv(conn->ssl[num].handle, buf, (int)buffersize, 0, timeout);
*wouldblock = FALSE;
if(nread < 0) {
/* failed SSL read */
PRInt32 err = PR_GetError();
if(err == PR_WOULD_BLOCK_ERROR) {
*wouldblock = TRUE;
return -1; /* basically EWOULDBLOCK */
}
if(err == PR_IO_TIMEOUT_ERROR) {
failf(data, "SSL connection timeout");
return CURLE_OPERATION_TIMEDOUT;
}
failf(conn->data, "SSL read: errno %d", err);
return -1;
}
return nread;
}
示例4: main
int main(int argc, char **argv)
{
if (test_common_init(&argc, &argv) != 0)
return -1;
nsresult rv;
#if defined(PR_LOGGING)
gTestLog = PR_NewLogModule("Test");
#endif
rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
if (NS_FAILED(rv))
return rv;
rv = RunTest();
if (NS_FAILED(rv))
LOG(("RunTest failed [rv=%x]\n", rv));
LOG(("sleeping main thread for 2 seconds...\n"));
PR_Sleep(PR_SecondsToInterval(2));
NS_ShutdownXPCOM(nullptr);
return 0;
}
示例5: PKIX_PL_Date_Create_CurrentOffBySeconds
/*
* FUNCTION: PKIX_PL_Date_Create_CurrentOffBySeconds
* (see comments in pkix_pl_pki.h)
*/
PKIX_Error *
PKIX_PL_Date_Create_CurrentOffBySeconds(
PKIX_Int32 secondsOffset,
PKIX_PL_Date **pDate,
void *plContext)
{
PKIX_PL_Date *date = NULL;
PRTime time;
PKIX_ENTER(DATE, "PKIX_PL_Date_Create_CurrentOffBySeconds");
PKIX_NULLCHECK_ONE(pDate);
time = PR_Now() + PR_SecondsToInterval(secondsOffset);
/* create a PKIX_PL_Date object */
PKIX_CHECK(PKIX_PL_Object_Alloc
(PKIX_DATE_TYPE,
sizeof (PKIX_PL_Date),
(PKIX_PL_Object **)&date,
plContext),
PKIX_COULDNOTCREATEOBJECT);
/* populate the nssTime field */
date->nssTime = time;
*pDate = date;
cleanup:
PKIX_RETURN(DATE);
}
示例6: AcceptThread
static void AcceptThread(void *arg)
{
PRIntn bytesRead;
char dataBuf[ACCEPT_READ_BUFSIZE];
PRFileDesc *arSock;
PRNetAddr *arAddr;
bytesRead = PR_AcceptRead( listenSock,
&arSock,
&arAddr,
dataBuf,
ACCEPT_READ_DATASIZE,
PR_SecondsToInterval(1));
if ( bytesRead == -1 && PR_GetError() == PR_IO_TIMEOUT_ERROR )
if ( debug ) printf("AcceptRead timed out\n");
else
if ( debug ) printf("Oops! read: %d, error: %d\n", bytesRead, PR_GetError());
while( state != AllDone ) {
PR_Lock( ml );
while( state != RunAcceptRead )
PR_WaitCondVar( cv, PR_INTERVAL_NO_TIMEOUT );
if ( ++iCounter >= jitter )
state = AllDone;
else
state = RunJitter;
if ( verbose ) printf(".");
PR_NotifyCondVar( cv );
PR_Unlock( ml );
PR_Write( file1, ".", 1 );
}
return;
} /* end AcceptThread() */
示例7: RunCloseTest
/**
* create transport, open streams, and close
*/
static nsresult
RunCloseTest(nsISocketTransportService *sts,
const char *host, int port,
uint32_t inFlags, uint32_t outFlags)
{
nsresult rv;
LOG(("RunCloseTest\n"));
nsCOMPtr<nsISocketTransport> transport;
rv = sts->CreateTransport(nullptr, 0,
nsDependentCString(host), port, nullptr,
getter_AddRefs(transport));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIInputStream> in;
rv = transport->OpenInputStream(inFlags, 0, 0, getter_AddRefs(in));
nsCOMPtr<nsIAsyncInputStream> asyncIn = do_QueryInterface(in, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIOutputStream> out;
rv = transport->OpenOutputStream(outFlags, 0, 0, getter_AddRefs(out));
nsCOMPtr<nsIAsyncOutputStream> asyncOut = do_QueryInterface(out, &rv);
if (NS_FAILED(rv)) return rv;
LOG(("waiting 1 second before closing transport and streams...\n"));
PR_Sleep(PR_SecondsToInterval(1));
// let nsCOMPtr destructors close everything...
return NS_OK;
}
示例8: snmp_collator_sem_wait
/*
* snmp_collator_sem_wait()
*
* A wrapper used to get the semaphore. We don't want to block,
* but we want to retry a specified number of times in case the
* semaphore is help by the sub-agent.
*/
static void
snmp_collator_sem_wait()
{
int i = 0;
int got_sem = 0;
if (SEM_FAILED == stats_sem) {
LDAPDebug1Arg(LDAP_DEBUG_ANY,
"semaphore for stats file (%s) is not available.\n", szStatsFile);
return;
}
for (i=0; i < SNMP_NUM_SEM_WAITS; i++) {
if (sem_trywait(stats_sem) == 0) {
got_sem = 1;
break;
}
PR_Sleep(PR_SecondsToInterval(1));
}
if (!got_sem) {
/* If we've been unable to get the semaphore, there's
* something wrong (likely the sub-agent went out to
* lunch). We remove the old semaphore and recreate
* a new one to avoid hanging up the server. */
sem_close(stats_sem);
sem_unlink(stats_sem_name);
snmp_collator_create_semaphore();
}
}
示例9: Java_org_mozilla_jss_ssl_SSLSocket_setSoLinger
/*
* linger
* The linger time, in seconds.
*/
JNIEXPORT void JNICALL
Java_org_mozilla_jss_ssl_SSLSocket_setSoLinger(JNIEnv *env, jobject self,
jboolean on, jint linger)
{
PRSocketOptionData sockOptions;
PRStatus status;
JSSL_SocketData *sock = NULL;
if( JSSL_getSockData(env, self, &sock) != PR_SUCCESS ) {
goto finish;
}
sockOptions.option = PR_SockOpt_Linger;
sockOptions.value.linger.polarity = on;
if(on) {
sockOptions.value.linger.linger = PR_SecondsToInterval(linger);
}
status = PR_SetSocketOption(sock->fd, &sockOptions);
if( status != PR_SUCCESS ) {
JSSL_throwSSLSocketException(env, "PR_SetSocketOption failed");
goto finish;
}
finish:
EXCEPTION_CHECK(env, sock)
return;
}
示例10: wifiScanner
nsresult
nsWifiMonitor::DoScan()
{
nsCOMArray<nsWifiAccessPoint> accessPoints;
mozilla::nsWifiScannerDBus wifiScanner(&accessPoints);
nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
while (mKeepGoing) {
accessPoints.Clear();
nsresult rv = wifiScanner.Scan();
NS_ENSURE_SUCCESS(rv, rv);
bool accessPointsChanged = !AccessPointsEqual(accessPoints,
lastAccessPoints);
ReplaceArray(lastAccessPoints, accessPoints);
rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
NS_ENSURE_SUCCESS(rv, rv);
LOG(("waiting on monitor\n"));
mozilla::ReentrantMonitorAutoEnter mon(mReentrantMonitor);
mon.Wait(PR_SecondsToInterval(kDefaultWifiScanInterval));
}
return NS_OK;
}
示例11: Serve_Client
/*
* Serve_Client
* Thread, started by the server, for serving a client connection.
* Reads data from socket and writes it back, unmodified, and
* closes the socket
*/
static void PR_CALLBACK
Serve_Client(void *arg)
{
Serve_Client_Param *scp = (Serve_Client_Param *) arg;
buffer *in_buf;
Session *sp;
PRJob *jobp;
sp = PR_NEW(Session);
sp->iod = scp->iod;
in_buf = PR_NEW(buffer);
if (in_buf == NULL) {
fprintf(stderr,"%s: failed to alloc buffer struct\n",program_name);
failed_already=1;
return;
}
sp->in_buf = in_buf;
sp->bytes = scp->datalen;
sp->msg_num = 0;
sp->bytes_read = 0;
sp->tp = scp->tp;
sp->exit_mon = scp->exit_mon;
sp->job_counterp = scp->job_counterp;
sp->iod.timeout = PR_SecondsToInterval(60);
jobp = PR_QueueJob_Read(sp->tp, &sp->iod, serve_client_read, sp,
PR_FALSE);
PR_ASSERT(NULL != jobp);
PR_DELETE(scp);
}
示例12: forked
static void PR_CALLBACK forked(void *arg)
{
PRIntn i;
PRLock *ml;
PRCondVar *cv;
PR_LogPrint("%s logging creating mutex\n", (const char*)arg);
ml = PR_NewLock();
PR_LogPrint("%s logging creating condition variable\n", (const char*)arg);
cv = PR_NewCondVar(ml);
PR_LogPrint("%s waiting on condition timeout 10 times\n", (const char*)arg);
for (i = 0; i < 10; ++i)
{
PR_Lock(ml);
PR_WaitCondVar(cv, PR_SecondsToInterval(1));
PR_Unlock(ml);
}
PR_LogPrint("%s logging destroying condition variable\n", (const char*)arg);
PR_DestroyCondVar(cv);
PR_LogPrint("%s logging destroying mutex\n", (const char*)arg);
PR_DestroyLock(ml);
PR_LogPrint("%s forked thread exiting\n", (const char*)arg);
}
示例13: TestIntervals
static void TestIntervals(void)
{
PRStatus rv;
PRUint32 delta;
PRInt32 seconds;
PRUint64 elapsed, thousand;
PRTime timein, timeout;
PRLock *ml = PR_NewLock();
PRCondVar *cv = PR_NewCondVar(ml);
for (seconds = 0; seconds < 10; ++seconds)
{
PRIntervalTime ticks = PR_SecondsToInterval(seconds);
PR_Lock(ml);
timein = PR_Now();
rv = PR_WaitCondVar(cv, ticks);
timeout = PR_Now();
PR_Unlock(ml);
LL_SUB(elapsed, timeout, timein);
LL_I2L(thousand, 1000);
LL_DIV(elapsed, elapsed, thousand);
LL_L2UI(delta, elapsed);
if (debug_mode) PR_fprintf(output,
"TestIntervals: %swaiting %ld seconds took %ld msecs\n",
((rv == PR_SUCCESS) ? "" : "FAILED "), seconds, delta);
}
PR_DestroyCondVar(cv);
PR_DestroyLock(ml);
if (debug_mode) PR_fprintf(output, "\n");
} /* TestIntervals */
示例14: _csngen_gen_tester_main
/* periodically generate a csn and dump it to the error log */
static void
_csngen_gen_tester_main (void *data)
{
CSNGen *gen = (CSNGen*)data;
CSN *csn = NULL;
char buff [CSN_STRSIZE];
int rc;
PR_ASSERT (gen);
while (!s_must_exit)
{
rc = csngen_new_csn (gen, &csn, PR_FALSE);
if (rc != CSN_SUCCESS)
{
slapi_log_err(SLAPI_LOG_ERR, "_csngen_gen_tester_main",
"failed to generate csn; csn error - %d\n", rc);
}
else
{
slapi_log_err(SLAPI_LOG_INFO, "_csngen_gen_tester_main", "generate csn %s\n",
csn_as_string(csn, PR_FALSE, buff));
}
csn_free(&csn);
/* sleep for 30 seconds */
DS_Sleep (PR_SecondsToInterval(10));
}
PR_AtomicDecrement (&s_thread_count);
}
示例15: Client
static void Client(const char *server_name)
{
PRStatus rv;
PRHostEnt host;
char buffer[PR_NETDB_BUF_SIZE];
PRIntervalTime dally = PR_SecondsToInterval(60);
PR_fprintf(err, "Translating the name %s\n", server_name);
rv = PR_GetHostByName(server_name, buffer, sizeof(buffer), &host);
if (PR_FAILURE == rv)
PL_FPrintError(err, "PR_GetHostByName");
else
{
if (PR_EnumerateHostEnt(
0, &host, PORT_NUMBER, &shared->server_address) < 0)
PL_FPrintError(err, "PR_EnumerateHostEnt");
else
{
do
{
shared->threads += 1;
(void)PR_CreateThread(
PR_USER_THREAD, Clientel, shared,
PR_PRIORITY_NORMAL, thread_scope,
PR_UNJOINABLE_THREAD, 8 * 1024);
if (shared->threads == initial_streams)
{
PR_Sleep(dally);
initial_streams += 1;
}
} while (PR_TRUE);
}
}
}