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;
95 if (status != ISC_R_SUCCESS) {
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)
157 return ISC_R_SUCCESS;
166 if (status != ISC_R_SUCCESS)
172 if (status != ISC_R_SUCCESS)
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));
241 if (status != ISC_R_SUCCESS) {
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) {
260 return ISC_R_SUCCESS;
266 const unsigned char *bufp,
271 int bytes_copied = 0;
285 return ISC_R_NOTCONNECTED;
288 for (
buffer = c -> outbufs;
293 if (status != ISC_R_SUCCESS)
298 while (bytes_copied < len) {
303 if (status != ISC_R_SUCCESS)
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,
323 if (status != ISC_R_SUCCESS)
328 &bufp [bytes_copied], copy_len);
329 buffer -> tail += copy_len;
330 c -> out_bytes += copy_len;
331 bytes_copied += copy_len;
336 status = ISC_R_SUCCESS;
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],
412 if (status != ISC_R_SUCCESS)
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);
445 return ISC_R_SUCCESS;
450 unsigned bytes_this_write;
462 return ISC_R_SUCCESS;
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,
530 if (status != ISC_R_SUCCESS) {
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;
577 return ISC_R_SUCCESS;
588 if (status != ISC_R_SUCCESS)
591 *result = ntohl (inbuf);
592 return ISC_R_SUCCESS;
600 inbuf = htonl (value);
614 if (status != ISC_R_SUCCESS)
617 *result = ntohs (inbuf);
618 return ISC_R_SUCCESS;
626 inbuf = htons (value);
642 switch (data -> type) {
645 if (status != ISC_R_SUCCESS)
653 if (status != ISC_R_SUCCESS)
657 (c, data -> u.
buffer.value,
659 return ISC_R_SUCCESS;
665 if (status != ISC_R_SUCCESS)
670 if (status != ISC_R_SUCCESS)
681 unsigned len = strlen (
name);
684 if (status != ISC_R_SUCCESS)
696 len = strlen (
string);
701 if (status != ISC_R_SUCCESS)
705 (c, (
const unsigned char *)
string, len);
706 return ISC_R_SUCCESS;
716 if (status != ISC_R_SUCCESS)
721 if (status != ISC_R_SUCCESS)
733 if (status != ISC_R_SUCCESS)
737 if (status != ISC_R_SUCCESS)
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_copyin(omapi_object_t *h, const unsigned char *bufp, unsigned len)
isc_result_t omapi_connection_put_named_uint32(omapi_object_t *c, const char *name, u_int32_t value)
omapi_connection_state_t state
#define DHCP_R_INVALIDARG
int log_error(const char *,...) __attribute__((__format__(__printf__
isc_result_t omapi_connection_put_string(omapi_object_t *c, const char *string)
isc_result_t omapi_connection_get_uint32(omapi_object_t *c, u_int32_t *result)
isc_result_t omapi_connection_copyout(unsigned char *buf, omapi_object_t *h, unsigned size)
struct omapi_typed_data_t::@3::@4 buffer
isc_result_t omapi_connection_put_handle(omapi_object_t *c, omapi_object_t *h)
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_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_put_name(omapi_object_t *c, const char *name)
isc_result_t omapi_connection_write_typed_data(omapi_object_t *c, omapi_typed_data_t *data)
isc_result_t omapi_object_handle(omapi_handle_t *, omapi_object_t *)
isc_result_t omapi_connection_put_uint32(omapi_object_t *c, u_int32_t value)
isc_result_t omapi_connection_reader(omapi_object_t *h)
isc_result_t omapi_connection_get_uint16(omapi_object_t *c, u_int16_t *result)
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_writer(omapi_object_t *h)
isc_result_t omapi_connection_put_uint16(omapi_object_t *c, u_int32_t value)
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_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)