The R Project SVN R

Rev

Rev 89135 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 89135 Rev 89706
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 
3
 
4
 *  Copyright (C) 1998-2023   The R Core Team
4
 *  Copyright (C) 1998-2026   The R Core Team
5
 *  Copyright (C) 1996, 1997  Robert Gentleman and Ross Ihaka
5
 *  Copyright (C) 1996, 1997  Robert Gentleman and Ross Ihaka
6
 *
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  the Free Software Foundation; either version 2 of the License, or
Line 293... Line 293...
293
	int maxfd = 0, howmany, i;
293
	int maxfd = 0, howmany, i;
294
	R_ProcessEvents();
294
	R_ProcessEvents();
295
#ifdef Unix
295
#ifdef Unix
296
	if(R_wait_usec > 0) {
296
	if(R_wait_usec > 0) {
297
	    int delta;
297
	    int delta;
298
	    if (mytimeout < 0 || R_wait_usec / 1e-6 < mytimeout - used)
298
	    if (mytimeout < 0 || R_wait_usec * 1e-6 < mytimeout - used)
299
		delta = R_wait_usec;
299
		delta = R_wait_usec;
300
	    else
300
	    else
301
		delta = (int)ceil(1e6 * (mytimeout - used));
301
		delta = (int)ceil(1e6 * (mytimeout - used));
302
	    tv.tv_sec = delta / 1000000;
302
	    tv.tv_sec = delta / 1000000; // integer div
303
	    tv.tv_usec = (suseconds_t)(delta - tv.tv_sec * 1000000);
303
	    tv.tv_usec = (suseconds_t)(delta - tv.tv_sec * 1000000);
304
	} else if (mytimeout >= 0) {
304
	} else if (mytimeout >= 0) {
305
	    tv.tv_sec = (int)(mytimeout - used);
305
	    tv.tv_sec = (int)(mytimeout - used);
306
	    tv.tv_usec = (int)ceil(1e6 * (mytimeout - used - tv.tv_sec));
306
	    tv.tv_usec = (int)ceil(1e6 * (mytimeout - used - tv.tv_sec));
307
	} else {  /* always poll occasionally--not really necessary */
307
	} else {  /* always poll occasionally--not really necessary */
Line 470... Line 470...
470
	status = R_SelectEx(maxfd+1, &rfd, &wfd, NULL, &tv, NULL);
470
	status = R_SelectEx(maxfd+1, &rfd, &wfd, NULL, &tv, NULL);
471
#endif
471
#endif
472
	if (R_socket_error(status))
472
	if (R_socket_error(status))
473
	    /* Ermm.. ?? */
473
	    /* Ermm.. ?? */
474
	    CLOSE_N_RETURN(-1);
474
	    CLOSE_N_RETURN(-1);
475
	    
475
 
476
	if (status == 0) {
476
	if (status == 0) {
477
	    /* Time out */
477
	    /* Time out */
478
	    if(used < timeout) continue;
478
	    if(used < timeout) continue;
479
	    CLOSE_N_RETURN(-1);
479
	    CLOSE_N_RETURN(-1);
480
	} else if ( FD_ISSET(s, &wfd) ) {
480
	} else if ( FD_ISSET(s, &wfd) ) {
Line 575... Line 575...
575
       before accept(), which depending on the OS may lead to accept()
575
       before accept(), which depending on the OS may lead to accept()
576
       blocking indefinitely, hence timeout not enforced. See chapter
576
       blocking indefinitely, hence timeout not enforced. See chapter
577
       16.6 of "UNIX Network Programming: The sockets networking API", vol 1,
577
       16.6 of "UNIX Network Programming: The sockets networking API", vol 1,
578
       Stevens, Fenner, Rudoff.
578
       Stevens, Fenner, Rudoff.
579
    */
579
    */
580
       
580
 
581
    while(1) {
581
    while(1) {
582
	R_ProcessEvents();
582
	R_ProcessEvents();
583
	set_timeval(&tv, timeout);
583
	set_timeval(&tv, timeout);
584
 
584
 
585
#ifdef Unix
585
#ifdef Unix