Mercurial > hg > xemacs-beta
annotate netinstall/simpsock.cc @ 1292:f3437b56874d
[xemacs-hg @ 2003-02-13 09:57:04 by ben]
profile updates
profile.c: Major reworking. Keep track of new information -- total
function timing (includes descendants), GC usage, total GC usage
(includes descendants). New functions to be called appropriately
from eval.c, alloc.c to keep track of this information. Keep track
of when we're actually in a function vs. in its profile, for more
accurate timing counts. Track profile overhead separately. Create
new mechanism for specifying "internal sections" that are tracked
just like regular Lisp functions and even appear in the backtrace
if `backtrace-with-internal-sections' is non-nil (t by default
for error-checking builds). Add some KKCC information for the
straight (non-Elisp) hash table used by profile, which contains
Lisp objects in its keys -- but not used yet. Remove old ad-hoc
methods for tracking garbage collection, redisplay (which was
incorrect anyway when Lisp was called within these sections).
Don't record any tick info when blocking under MS Windows, since
the timer there is in real time rather than in process time.
Make `start-profiling', `stop-profiling' interactive. Be consistent
wrt. recursive functions and functions currently on the stack when
starting or stopping -- together these make implementing the
`total' values extremely difficult. When we start profiling, we
act as if we just entered all the functions currently on the stack.
Likewise when exiting. Create vars in_profile for tracking
time spent inside of profiling, and profiling_lock for setting
exclusive access to the main hash table when reading from it or
modifying it. (protects against getting screwed up by the signal
handle going off at the same time.
profile.h: New file.
Create macros for declaring internal profiling sections.
lisp.h: Move profile-related stuff to profile.h.
alloc.c: Keep track of total consing, for profile.
Tell profile when we are consing.
Use new profile-section method for noting garbage-collection.
alloc.c: Abort if we attempt to call the allocator reentrantly.
backtrace.h, eval.c: Add info for use by profile in the backtrace frame and transfer
PUSH_BACKTRACE/POP_BACKTRACE from eval.c, for use with profile.
elhash.c: Author comment.
eval.c, lisp.h: New Lisp var `backtrace-with-internal-sections'. Set to t when
error-checking is on.
eval.c: When unwinding,
eval.c: Report to profile when we are about-to-call and just-called wrt. a
function.
alloc.c, eval.c: Allow for "fake" backtrace frames, for internal sections (used by
profile and `backtrace-with-internal-sections'.
event-Xt.c, event-gtk.c, event-msw.c, event-tty.c: Record when we are actually blocking on an event, for profile's sake.
event-stream.c: Record internal profiling sections for getting, dispatching events.
extents.c: Record internal profiling sections for map_extents.
hash.c, hash.h: Add pregrow_hash_table_if_necessary(). (Used in profile code
since the signal handler is the main grower but can't allow
a realloc(). We make sure, at critical points, that the table
is large enough.)
lread.c: Create internal profiling sections for `load' (which may be triggered
internally by autoload, etc.).
redisplay.c: Remove old profile_redisplay_flag. Use new macros to declare
internal profiling section for redisplay.
text.c: Use new macros to declare internal profiling sections for
char-byte conversion and internal-external conversion.
SEMI-UNRELATED CHANGES:
-----------------------
text.c: Update the long comments.
author | ben |
---|---|
date | Thu, 13 Feb 2003 09:57:08 +0000 |
parents | 3078fd1074e8 |
children |
rev | line source |
---|---|
448 | 1 /* |
2 * Copyright (c) 2000, Red Hat, Inc. | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * A copy of the GNU General Public License can be found at | |
10 * http://www.gnu.org/ | |
11 * | |
12 * Written by DJ Delorie <dj@cygnus.com> | |
13 * | |
14 */ | |
15 | |
16 /* Simplified socket access functions */ | |
17 | |
18 #include "win32.h" | |
19 #include <winsock.h> | |
20 #include <stdio.h> | |
21 #include <stdarg.h> | |
22 #include <stdlib.h> | |
23 | |
24 #include "simpsock.h" | |
25 #include "msg.h" | |
26 | |
27 #define SSBUFSZ 1024 | |
28 | |
29 SimpleSocket::SimpleSocket (char *hostname, int port) | |
30 { | |
31 static int initted = 0; | |
32 if (!initted) | |
33 { | |
34 initted = 1; | |
35 WSADATA d; | |
36 WSAStartup (MAKEWORD (1,1), &d); | |
37 } | |
38 | |
39 s = INVALID_SOCKET; | |
40 buf = (char *) malloc (SSBUFSZ + 3); | |
41 putp = getp = 0; | |
42 | |
43 int i1, i2, i3, i4; | |
44 unsigned char ip[4]; | |
45 | |
46 if (sscanf (hostname, "%d.%d.%d.%d", &i1, &i2, &i3, &i4) == 4) | |
47 { | |
48 ip[0] = i1; | |
49 ip[1] = i2; | |
50 ip[2] = i3; | |
51 ip[3] = i4; | |
52 } | |
53 else | |
54 { | |
55 struct hostent *he; | |
56 he = gethostbyname (hostname); | |
57 if (!he) | |
58 { | |
59 msg ("Can't resolve `%s'\n", hostname); | |
60 return; | |
61 } | |
62 memcpy (ip, he->h_addr_list[0], 4); | |
63 } | |
64 | |
65 s = socket (AF_INET, SOCK_STREAM, 0); | |
66 if (s == INVALID_SOCKET) | |
67 { | |
68 msg ("Can't create socket, %d", WSAGetLastError ()); | |
69 return; | |
70 } | |
71 | |
72 struct sockaddr_in name; | |
73 | |
74 memset (&name, 0, sizeof (name)); | |
75 name.sin_family = AF_INET; | |
76 name.sin_port = htons (port); | |
77 memcpy (&name.sin_addr, ip, 4); | |
78 | |
79 if (connect (s, (sockaddr *)&name, sizeof(name))) | |
80 { | |
81 msg ("Can't connect to %s:%d", hostname, port); | |
82 closesocket (s); | |
83 s = INVALID_SOCKET; | |
84 return; | |
85 } | |
86 | |
87 return; | |
88 } | |
89 | |
90 SimpleSocket::~SimpleSocket () | |
91 { | |
92 if (s != INVALID_SOCKET) | |
93 closesocket (s); | |
94 s = INVALID_SOCKET; | |
95 if (buf) | |
96 free (buf); | |
97 buf = 0; | |
98 } | |
99 | |
100 int | |
101 SimpleSocket::ok () | |
102 { | |
103 if (s == INVALID_SOCKET) | |
104 return 0; | |
105 return 1; | |
106 } | |
107 | |
108 int | |
109 SimpleSocket::printf (char *fmt, ...) | |
110 { | |
111 char localbuf[SSBUFSZ]; | |
112 va_list args; | |
113 va_start (args, fmt); | |
114 vsprintf (localbuf, fmt, args); | |
115 return send (s, localbuf, strlen (localbuf), 0); | |
116 } | |
117 | |
118 int | |
119 SimpleSocket::write (char *localbuf, int len) | |
120 { | |
121 return send (s, localbuf, len, 0); | |
122 } | |
123 | |
124 int | |
125 SimpleSocket::fill () | |
126 { | |
127 if (putp == getp) | |
128 putp = getp = 0; | |
129 | |
130 int n = SSBUFSZ - putp; | |
131 if (n == 0) | |
132 return 0; | |
133 int r = recv (s, buf + putp, n, 0); | |
134 if (r > 0) | |
135 { | |
136 putp += r; | |
137 return r; | |
138 } | |
139 return 0; | |
140 } | |
141 | |
142 char * | |
143 SimpleSocket::gets () | |
144 { | |
145 if (getp > 0 && putp > getp) | |
146 { | |
147 memmove (buf, buf+getp, putp-getp); | |
148 putp -= getp; | |
149 getp = 0; | |
150 } | |
151 if (putp == getp) | |
152 fill(); | |
153 | |
154 // getp is zero, always, here, and putp is the count | |
155 char *nl; | |
156 while ((nl = (char *)memchr (buf, '\n', putp)) == NULL && putp < SSBUFSZ) | |
157 if (fill () <= 0) | |
158 break; | |
159 | |
160 if (nl) | |
161 { | |
162 getp = nl - buf + 1; | |
163 while ((*nl == '\n' || *nl == '\r') && nl >= buf) | |
164 *nl-- = 0; | |
165 } | |
166 else | |
167 { | |
168 getp = putp; | |
169 nl = buf + putp; | |
170 nl[1] = 0; | |
171 } | |
172 | |
173 return buf; | |
174 } | |
175 | |
176 #define MIN(a,b) ((a) < (b) ? (a) : (b)) | |
177 | |
178 int | |
179 SimpleSocket::read (char *ubuf, int ulen) | |
180 { | |
181 int n, rv=0; | |
182 if (putp > getp) | |
183 { | |
184 n = MIN (ulen, putp-getp); | |
185 memmove (ubuf, buf+getp, n); | |
186 getp += n; | |
187 ubuf += n; | |
188 ulen -= n; | |
189 rv += n; | |
190 } | |
191 while (ulen > 0) | |
192 { | |
193 n = recv (s, ubuf, ulen, 0); | |
194 if (n <= 0) | |
195 return rv; | |
196 ubuf += n; | |
197 ulen -= n; | |
198 rv += n; | |
199 } | |
200 return rv; | |
201 } |