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)
161 for (buffer = c -> inbufs; buffer -> next;
162 buffer = buffer -> next)
168 buffer = buffer -> next;
174 buffer = c -> inbufs;
179 while (bytes_to_read) {
180 if (buffer -> tail > buffer -> head)
181 read_len =
sizeof (buffer -> buf) - buffer -> tail;
183 read_len = buffer -> head - buffer -> tail;
185 #if defined (TRACING)
188 if (read_len > stuff_len)
189 read_len = stuff_len;
191 *stuff_taken += read_len;
192 memcpy (&buffer -> buf [buffer -> tail],
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,
204 &buffer -> buf [buffer -> tail],
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;
236 iov [1].
buf = &buffer -> buf [buffer -> tail];
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;
250 if (buffer -> tail ==
sizeof buffer -> buf)
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;
289 buffer -> next; buffer = buffer -> next)
295 buffer = c -> outbufs;
298 while (bytes_copied < len) {
305 buffer = buffer -> next;
308 if (buffer -> tail > buffer -> head)
309 copy_len =
sizeof (buffer -> buf) - buffer -> tail;
311 copy_len = buffer -> head - buffer -> tail;
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,
327 memcpy (&buffer -> buf [buffer -> tail],
328 &bufp [bytes_copied], copy_len);
329 buffer -> tail += copy_len;
330 c -> out_bytes += copy_len;
331 bytes_copied += copy_len;
332 if (buffer -> tail ==
sizeof buffer -> buf)
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;
380 buffer = c -> inbufs;
382 while (bytes_remaining) {
384 return ISC_R_UNEXPECTED;
386 if (buffer -> head == (
sizeof buffer -> buf) - 1)
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;
426 buffer = buffer -> next;
431 while (c -> inbufs &&
433 if (c -> inbufs -> next) {
435 c -> inbufs -> next,
MDL);
441 (&c -> inbufs, buffer,
MDL);
450 unsigned bytes_this_write;
464 buffer = c -> outbufs;
466 while (c -> out_bytes) {
468 return ISC_R_UNEXPECTED;
470 if (buffer -> head == (
sizeof buffer -> buf) - 1)
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;
524 iov [1].
buf = &buffer -> buf [buffer -> tail];
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;
550 buffer = buffer -> next;
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);
isc_result_t omapi_connection_reader(omapi_object_t *)
omapi_object_type_t * omapi_type_connection
#define BUFFER_BYTES_FREE(x)
isc_result_t omapi_buffer_dereference(omapi_buffer_t **, const char *, int)
isc_result_t omapi_connection_put_handle(omapi_object_t *c, omapi_object_t *h)
isc_result_t omapi_connection_copyin(omapi_object_t *, const unsigned char *, unsigned)
isc_result_t omapi_connection_put_named_uint32(omapi_object_t *, const char *, u_int32_t)
omapi_connection_state_t state
int log_error(const char *,...) __attribute__((__format__(__printf__
struct omapi_typed_data_t::@3::@4 buffer
isc_result_t omapi_connection_put_uint32(omapi_object_t *, u_int32_t)
isc_result_t omapi_connection_write_typed_data(omapi_object_t *, omapi_typed_data_t *)
trace_type_t * trace_type_register(const char *, void *, void(*)(trace_type_t *, unsigned, char *), void(*)(trace_type_t *), const char *, int)
isc_result_t omapi_connection_writer(omapi_object_t *)
isc_result_t omapi_signal(omapi_object_t *, const char *,...)
isc_result_t trace_write_packet_iov(trace_type_t *, int, trace_iov_t *, const char *, int)
isc_result_t omapi_connection_get_uint32(omapi_object_t *, u_int32_t *)
isc_result_t omapi_object_handle(omapi_handle_t *, omapi_object_t *)
isc_result_t omapi_connection_put_string(omapi_object_t *, const char *)
unsigned int omapi_handle_t
isc_result_t omapi_buffer_reference(omapi_buffer_t **, omapi_buffer_t *, const char *, int)
isc_result_t omapi_connection_put_uint16(omapi_object_t *, u_int32_t)
omapi_object_type_t * omapi_type_io_object
void omapi_buffer_trace_setup(void)
#define omapi_array_foreach_end(array, stype, var)
#define BYTES_IN_BUFFER(x)
omapi_type_protocol_listener omapi_type_listener omapi_type_waiter omapi_type_message isc_result_t omapi_connection_sign_data(int mode, dst_key_t *key, void **context, const unsigned char *data, const unsigned len, omapi_typed_data_t **result)
isc_result_t omapi_connection_copyout(unsigned char *, omapi_object_t *, unsigned)
isc_result_t omapi_connection_get_uint16(omapi_object_t *, u_int16_t *)
isc_result_t omapi_connection_put_name(omapi_object_t *, const char *)
isc_result_t omapi_disconnect(omapi_object_t *, int)
#define omapi_array_foreach_begin(array, stype, var)
isc_result_t omapi_buffer_new(omapi_buffer_t **, const char *, int)