35 static void trace_connection_input_input (
trace_type_t *,
unsigned,
char *);
36 static void trace_connection_input_stop (
trace_type_t *);
37 static void trace_connection_output_input (
trace_type_t *,
unsigned,
char *);
38 static void trace_connection_output_stop (
trace_type_t *);
41 static isc_result_t omapi_connection_reader_trace (
omapi_object_t *,
48 trace_connection_input =
51 trace_connection_input_input,
52 trace_connection_input_stop,
MDL);
53 trace_connection_output =
56 trace_connection_output_input,
57 trace_connection_output_stop,
MDL);
60 static void trace_connection_input_input (
trace_type_t *ttype,
61 unsigned length,
char *buf)
63 unsigned left, taken, cc = 0;
65 int32_t connect_index;
69 memcpy (&connect_index, buf,
sizeof connect_index);
70 connect_index = ntohl (connect_index);
74 if (lp -> index == ntohl (connect_index)) {
75 omapi_connection_reference (&c, lp,
MDL);
76 omapi_connection_dereference (&lp,
MDL);
83 log_error (
"trace connection input: no connection index %ld",
84 (
long int)connect_index);
88 s = buf +
sizeof connect_index;
89 left = length -
sizeof connect_index;
97 isc_result_totext (status));
103 "input is not being consumed.");
112 omapi_connection_dereference (&c,
MDL);
115 static void trace_connection_input_stop (
trace_type_t *ttype) { }
117 static void trace_connection_output_input (
trace_type_t *ttype,
118 unsigned length,
char *buf)
124 static void trace_connection_output_stop (
trace_type_t *ttype) { }
133 #if defined (TRACING)
134 return omapi_connection_reader_trace (h, 0, (
char *)0, (
unsigned *)0);
137 static isc_result_t omapi_connection_reader_trace (
omapi_object_t *h,
140 unsigned *stuff_taken)
148 unsigned bytes_to_read;
156 c -> in_bytes > c -> bytes_needed)
179 while (bytes_to_read) {
185 #if defined (TRACING)
188 if (read_len > stuff_len)
189 read_len = stuff_len;
191 *stuff_taken += read_len;
193 stuff_buf, read_len);
194 stuff_len -= read_len;
195 stuff_buf += read_len;
196 read_status = read_len;
203 read_status = read (c -> socket,
207 if (read_status < 0) {
208 if (errno == EWOULDBLOCK)
210 else if (errno == EIO)
211 return ISC_R_IOERROR;
212 else if (errno == EINVAL)
214 else if (errno == ECONNRESET) {
216 return ISC_R_SHUTTINGDOWN;
218 return ISC_R_UNEXPECTED;
223 if (read_status == 0) {
225 return ISC_R_SHUTTINGDOWN;
227 #if defined (TRACING)
230 int32_t connect_index;
232 connect_index = htonl (c -> index);
234 iov [0].
buf = (
char *)&connect_index;
235 iov [0].
len =
sizeof connect_index;
237 iov [1].
len = read_status;
240 (trace_connection_input, 2, iov,
MDL));
244 isc_result_totext (status));
248 buffer -> tail += read_status;
249 c -> in_bytes += read_status;
252 if (read_status < read_len)
254 bytes_to_read -= read_status;
257 if (c -> bytes_needed <= c -> in_bytes) {
266 const unsigned char *bufp,
271 int bytes_copied = 0;
285 return ISC_R_NOTCONNECTED;
288 for (
buffer = c -> outbufs;
298 while (bytes_copied < len) {
313 if (copy_len > (len - bytes_copied))
314 copy_len = len - bytes_copied;
317 if (!c -> out_context)
320 (sig_flags, c -> out_key, &c -> out_context,
321 &bufp [bytes_copied], copy_len,
328 &bufp [bytes_copied], copy_len);
329 buffer -> tail += copy_len;
330 c -> out_bytes += copy_len;
331 bytes_copied += copy_len;
345 if ((c->outer != NULL) &&
348 isc_socket_fdwatchpoke(io->
fd,
349 ISC_SOCKFDWATCH_WRITE);
363 unsigned bytes_remaining;
364 unsigned bytes_this_copy;
376 if (size > c -> in_bytes)
379 bytes_remaining = size;
382 while (bytes_remaining) {
384 return ISC_R_UNEXPECTED;
389 first_byte =
buffer -> head + 1;
391 if (first_byte >
buffer -> tail) {
392 bytes_this_copy = (
sizeof buffer -> buf -
396 buffer -> tail - first_byte;
398 if (bytes_this_copy > bytes_remaining)
399 bytes_this_copy = bytes_remaining;
402 if (!c -> in_context)
409 &
buffer -> buf [first_byte],
416 memcpy (bufp, &
buffer -> buf [first_byte],
418 bufp += bytes_this_copy;
420 bytes_remaining -= bytes_this_copy;
421 buffer -> head = first_byte + bytes_this_copy - 1;
422 c -> in_bytes -= bytes_this_copy;
431 while (c -> inbufs &&
433 if (c -> inbufs -> next) {
435 c -> inbufs -> next,
MDL);
450 unsigned bytes_this_write;
466 while (c -> out_bytes) {
468 return ISC_R_UNEXPECTED;
473 first_byte =
buffer -> head + 1;
475 if (first_byte >
buffer -> tail) {
476 bytes_this_write = (
sizeof buffer -> buf -
480 buffer -> tail - first_byte;
482 bytes_written = write (c -> socket,
483 &
buffer -> buf [first_byte],
489 if (bytes_written < 0) {
490 if (errno == EWOULDBLOCK || errno == EAGAIN)
491 return ISC_R_INPROGRESS;
492 else if (errno == EPIPE)
495 else if (errno == EFBIG || errno == EDQUOT)
497 else if (errno == EFBIG)
499 return ISC_R_NORESOURCES;
500 else if (errno == ENOSPC)
501 return ISC_R_NOSPACE;
502 else if (errno == EIO)
503 return ISC_R_IOERROR;
504 else if (errno == EINVAL)
506 else if (errno == ECONNRESET)
507 return ISC_R_SHUTTINGDOWN;
509 return ISC_R_UNEXPECTED;
511 if (bytes_written == 0)
512 return ISC_R_INPROGRESS;
514 #if defined (TRACING)
518 int32_t connect_index;
520 connect_index = htonl (c -> index);
522 iov [0].
buf = (
char *)&connect_index;
523 iov [0].
len =
sizeof connect_index;
525 iov [1].
len = bytes_written;
528 (trace_connection_input, 2, iov,
534 isc_result_totext (status));
539 buffer -> head = first_byte + bytes_written - 1;
540 c -> out_bytes -= bytes_written;
545 if (bytes_written != bytes_this_write)
546 return ISC_R_INPROGRESS;
555 while (c -> outbufs &&
557 if (c -> outbufs -> next) {
559 c -> outbufs -> next,
MDL);
574 return ISC_R_SHUTTINGDOWN;
591 *result = ntohl (inbuf);
600 inbuf = htonl (
value);
617 *result = ntohs (inbuf);
626 inbuf = htons (
value);
642 switch (data -> type) {
657 (c, data -> u.
buffer.value,
681 unsigned len = strlen (name);
696 len = strlen (
string);
705 (c, (
const unsigned char *)
string, len);