4 * Author: Teemu Rantanen <tvr@cs.hut.fi>
5 * Copyright (c) 1992 Teemu Rantanen
8 * Created: Mon Apr 20 19:29:14 1992 tvr
9 * Last modified: Wed May 13 00:53:24 1992 tvr
14 #include <sys/types.h>
24 #include "../HText/HText.h"
26 extern HText_t *HtLocalText;
30 * Poll connecting until connection completes.
37 CL_DEBUG (("Poll connect\n"));
39 status = connect (WWWErwiseConnection->fd,
40 (struct sockaddr *) WWWErwiseConnection->addr,
41 WWWErwiseConnection->addr_size);
42 if (status < 0 && (errno != EISCONN))
44 if ((errno == EALREADY) || (errno == EINPROGRESS))
52 CL_DEBUG (("Cannot connect(%d)\n", errno));
57 WWWErwiseStatus = CL_FAILED;
63 * Connected. Get next function from the list of things to do.
67 free (WWWErwiseConnection->addr);
69 WWWErwiseConnection->addr = NULL;
71 WWWErwiseConnection->function++;
77 * Instead of connect, this function is called. Store needed data to
78 * poll connecting later.
81 erwise_connect (fd, addr, size)
83 struct sockaddr *addr;
88 CL_DEBUG (("Try to Connect\n"));
90 status = connect (fd, addr, size);
102 CL_DEBUG (("Cannot connect (first try %d)\n", errno));
108 * Duplicate what to connect
110 WWWErwiseConnection->addr = (void *) malloc (size);
112 memcpy (WWWErwiseConnection->addr, addr, size);
114 WWWErwiseConnection->addr_size = size;
127 * Send command to net
131 WWWErwiseSendCommand ()
135 CL_DEBUG (("Send Command\n"));
137 status = NETWRITE (WWWErwiseConnection->fd,
138 WWWErwiseConnection->command,
139 (int) strlen (WWWErwiseConnection->command));
141 if (status == strlen (WWWErwiseConnection->command))
146 free (WWWErwiseConnection->command);
147 WWWErwiseConnection->command = 0;
149 WWWErwiseConnection->function++;
157 CL_DEBUG (("SendCommand failed\n"));
159 WWWErwiseStatus = CL_FAILED;
167 char *tmp = WWWErwiseConnection->command;
169 WWWErwiseConnection->command = (char *) strdup (tmp + status);
175 #define ERWISE_BLOCK 8192
178 * Read data until all data is read
184 char tmp[ERWISE_BLOCK];
188 i = read (WWWErwiseConnection->fd,
192 CL_DEBUG (("got %d bytes\n", i));
195 * Append data to (memory) buffer or to file.
201 * Load directly to file ?
204 if (WWWErwiseConnection->load_to_file)
208 st = write (WWWErwiseConnection->load_to_file_fd,
214 WWWErwiseStatus = CL_FAILED;
220 if (!WWWErwiseConnection->buffer_first)
223 WWWErwiseConnection->buffer_first =
224 WWWErwiseConnection->buffer_last =
225 (cl_data_t *) malloc (sizeof (cl_data_t));
227 memset (WWWErwiseConnection->buffer_first, 0, sizeof (cl_data_t));
229 WWWErwiseConnection->buffer_first->data =
230 WWWErwiseConnection->buffer_first->freeptr =
233 WWWErwiseConnection->buffer_first->size = i;
235 memcpy (WWWErwiseConnection->buffer_first->data, tmp, i);
241 cl_data_t *p = (cl_data_t *) malloc (sizeof (cl_data_t));
243 memset (p, 0, sizeof (cl_data_t));
245 p->data = p->freeptr = (void *) malloc (i);
249 memcpy (p->data, tmp, i);
251 p->prev = WWWErwiseConnection->buffer_last;
253 WWWErwiseConnection->buffer_last->next = p;
255 WWWErwiseConnection->buffer_last = p;
261 if (i < 0 && (errno != EWOULDBLOCK))
263 CL_DEBUG (("ReadData failed\n"));
264 WWWErwiseStatus = CL_FAILED;
269 WWWErwiseConnection->function++;
277 * Parse data that has been read
284 * XXXXXX If saving to file, don't parse
287 HTParseFormat (WWWErwiseConnection->diag ? WWW_PLAINTEXT : WWW_HTML,
288 WWWErwiseConnection->anAnchor,
289 WWWErwiseConnection->fd);
291 (void) HTClose (WWWErwiseConnection->fd);
294 * XXXXX free connection structure
296 WWWErwiseStatus = CL_COMPLETED;
297 WWWErwiseConnection->function++;
303 * If we are loading to file, nothing else needs to be done ...
306 WWWErwiseTerminateIfLoadToFile ()
308 if (WWWErwiseConnection->load_to_file)
312 while (*WWWErwiseConnection->function)
314 WWWErwiseConnection->function++;
317 WWWErwiseStatus = CL_COMPLETED;
322 WWWErwiseConnection->function++;