Print this page
4823 don't open-code NSEC2MSEC and MSEC2NSEC
   1 /*
   2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
   3  * Use is subject to license terms.
   4  */
   5 
   6 #pragma ident   "%Z%%M% %I%     %E% SMI"
   7 
   8 /*
   9  * The contents of this file are subject to the Netscape Public
  10  * License Version 1.1 (the "License"); you may not use this file
  11  * except in compliance with the License. You may obtain a copy of
  12  * the License at http://www.mozilla.org/NPL/
  13  *
  14  * Software distributed under the License is distributed on an "AS
  15  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  16  * implied. See the License for the specific language governing
  17  * rights and limitations under the License.
  18  *
  19  * The Original Code is Mozilla Communicator client code, released
  20  * March 31, 1998.
  21  *
  22  * The Initial Developer of the Original Code is Netscape
  23  * Communications Corporation. Portions created by Netscape are
  24  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  25  * Rights Reserved.
  26  *
  27  * Contributor(s):


 300         FD_ZERO(&rset);
 301         FD_SET(sockfd, &rset);
 302         wset = rset;
 303 
 304 #ifdef _WINDOWS
 305         eset = rset;
 306 #endif /* _WINDOWS */
 307 
 308         if (msec < 0 && msec != LDAP_X_IO_TIMEOUT_NO_TIMEOUT) {
 309                 LDAPDebug( LDAP_DEBUG_TRACE, "Invalid timeout value detected.."
 310                         "resetting connect timeout to default value "
 311                         "(LDAP_X_IO_TIMEOUT_NO_TIMEOUT\n", 0, 0, 0);
 312                 msec = LDAP_X_IO_TIMEOUT_NO_TIMEOUT;
 313         } else {
 314                 if (msec != 0) {
 315                         tval.tv_sec = msec / MILLISEC;
 316                         tval.tv_usec = (MICROSEC / MILLISEC) *
 317                                             (msec % MILLISEC);
 318 #ifdef _SOLARIS_SDK
 319                         start_time = gethrtime();
 320                         tv_time = (hrtime_t)msec * (NANOSEC / MILLISEC);
 321 #else
 322                         start_time = (long)time(NULL);
 323 #endif
 324                 } else {
 325                         tval.tv_sec = 0;
 326                         tval.tv_usec = 0;
 327                 }
 328         }
 329 
 330         /* if timeval structure == NULL, select will block indefinitely */
 331         /*                      != NULL, and value == 0, select will */
 332         /*                               not block */
 333         /* Windows is a bit quirky on how it behaves w.r.t nonblocking */
 334         /* connects.  If the connect fails, the exception fd, eset, is */
 335         /* set to show the failure.  The first argument in select is */
 336         /* ignored */
 337 
 338 #ifdef _WINDOWS
 339         if ((n = select(sockfd +1, &rset, &wset, &eset,
 340                 (msec != LDAP_X_IO_TIMEOUT_NO_TIMEOUT) ? &tval : NULL)) == 0) {


   1 /*
   2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
   3  * Use is subject to license terms.
   4  */
   5 


   6 /*
   7  * The contents of this file are subject to the Netscape Public
   8  * License Version 1.1 (the "License"); you may not use this file
   9  * except in compliance with the License. You may obtain a copy of
  10  * the License at http://www.mozilla.org/NPL/
  11  *
  12  * Software distributed under the License is distributed on an "AS
  13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  14  * implied. See the License for the specific language governing
  15  * rights and limitations under the License.
  16  *
  17  * The Original Code is Mozilla Communicator client code, released
  18  * March 31, 1998.
  19  *
  20  * The Initial Developer of the Original Code is Netscape
  21  * Communications Corporation. Portions created by Netscape are
  22  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  23  * Rights Reserved.
  24  *
  25  * Contributor(s):


 298         FD_ZERO(&rset);
 299         FD_SET(sockfd, &rset);
 300         wset = rset;
 301 
 302 #ifdef _WINDOWS
 303         eset = rset;
 304 #endif /* _WINDOWS */
 305 
 306         if (msec < 0 && msec != LDAP_X_IO_TIMEOUT_NO_TIMEOUT) {
 307                 LDAPDebug( LDAP_DEBUG_TRACE, "Invalid timeout value detected.."
 308                         "resetting connect timeout to default value "
 309                         "(LDAP_X_IO_TIMEOUT_NO_TIMEOUT\n", 0, 0, 0);
 310                 msec = LDAP_X_IO_TIMEOUT_NO_TIMEOUT;
 311         } else {
 312                 if (msec != 0) {
 313                         tval.tv_sec = msec / MILLISEC;
 314                         tval.tv_usec = (MICROSEC / MILLISEC) *
 315                                             (msec % MILLISEC);
 316 #ifdef _SOLARIS_SDK
 317                         start_time = gethrtime();
 318                         tv_time = MSEC2NSEC(msec);
 319 #else
 320                         start_time = (long)time(NULL);
 321 #endif
 322                 } else {
 323                         tval.tv_sec = 0;
 324                         tval.tv_usec = 0;
 325                 }
 326         }
 327 
 328         /* if timeval structure == NULL, select will block indefinitely */
 329         /*                      != NULL, and value == 0, select will */
 330         /*                               not block */
 331         /* Windows is a bit quirky on how it behaves w.r.t nonblocking */
 332         /* connects.  If the connect fails, the exception fd, eset, is */
 333         /* set to show the failure.  The first argument in select is */
 334         /* ignored */
 335 
 336 #ifdef _WINDOWS
 337         if ((n = select(sockfd +1, &rset, &wset, &eset,
 338                 (msec != LDAP_X_IO_TIMEOUT_NO_TIMEOUT) ? &tval : NULL)) == 0) {