Watt-32 tcp/ip  2.2 dev-rel.10
nettime.c
Go to the documentation of this file.
1 
5 /* BSD sockets functionality for Watt-32 TCP/IP
6  *
7  * Copyright (c) 1997-2002 Gisle Vanem <gvanem@yahoo.no>
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  * must display the following acknowledgement:
19  * This product includes software developed by Gisle Vanem
20  * Bergen, Norway.
21  *
22  * THIS SOFTWARE IS PROVIDED BY ME (Gisle Vanem) AND CONTRIBUTORS ``AS IS''
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL I OR CONTRIBUTORS BE LIABLE FOR ANY
26  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *
34  * 14.may 1999 (GV) - Created
35  *
36  * This module implements time counters for "user" and "system"
37  * calls. NOTE: "system" time is counted only when signals are
38  * trapped. i.e. around select_s(), connect() loops.
39  *
40  * Based on djgpp version of times().
41  *
42  */
43 
44 #include "socket.h"
45 
46 #if defined(USE_BSD_API)
47 
48 static DWORD sock_sys_time;
49 static DWORD start;
50 
51 void _sock_start_timer (void)
52 {
53  start = set_timeout (0);
54 }
55 
56 void _sock_stop_timer (void)
57 {
58  DWORD now = set_timeout (0);
59 
60  if (now > start)
61  sock_sys_time += (now - start);
62  else sock_sys_time += (start - now); /* msec/tick counter wrapped */
63 }
64 
65 static DWORD sys_time (void)
66 {
67  return (sock_sys_time);
68 }
69 
70 static DWORD usr_time (void)
71 {
72  return (set_timeout(0) - start_time - sock_sys_time);
73 }
74 
75 unsigned long W32_CALL net_times (struct tms *tms)
76 {
77  if (!tms)
78  {
79  SOCK_ERRNO (EINVAL);
80  return (unsigned long)(-1);
81  }
82  memset (tms, 0, sizeof(*tms));
83  if (_watt_is_init)
84  {
85 #ifdef WIN32
86  DWORD divisor = 1000;
87 #else
88  DWORD divisor = (has_8254 || has_rdtsc) ? 1000 : 18;
89 #endif
90 
91  tms->tms_utime = (CLOCKS_PER_SEC * usr_time()) / divisor;
92  tms->tms_stime = (CLOCKS_PER_SEC * sys_time()) / divisor;
93  }
94  return (tms->tms_utime);
95 }
96 #endif /* USE_BSD_API */
97 
BOOL _watt_is_init
watt_sock_init() done (but with possible failed boot)
Definition: sock_ini.c:157
BOOL has_rdtsc
Never set in Watt-32.
Definition: timer.c:52
DWORD W32_CALL set_timeout(DWORD msec)
Return time for when given timeout (msec) expires.
Definition: timer.c:503
BOOL has_8254
Do we have a working 8254 timer chip?
Definition: timer.c:56
DWORD start_time
Start-time of watt_sock_init() (in msec)
Definition: timer.c:47
Definition: wtime.h:53