Merge Monty
[awesomized/libmemcached] / libmemcached / io.c
1 /* LibMemcached
2 * Copyright (C) 2006-2009 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary: Server IO, Not public!
9 *
10 */
11
12
13 #include "common.h"
14 #include <sys/select.h>
15 #include <poll.h>
16
17 typedef enum {
18 MEM_READ,
19 MEM_WRITE
20 } memc_read_or_write;
21
22 static ssize_t io_flush(memcached_server_write_instance_st ptr,
23 memcached_return_t *error);
24 static void increment_udp_message_id(memcached_server_write_instance_st ptr);
25
26 static memcached_return_t io_wait(memcached_server_write_instance_st ptr,
27 memc_read_or_write read_or_write)
28 {
29 struct pollfd fds= {
30 .fd= ptr->fd,
31 .events = POLLIN
32 };
33 int error;
34
35 if (read_or_write == MEM_WRITE) /* write */
36 {
37 fds.events= POLLOUT;
38 WATCHPOINT_SET(ptr->io_wait_count.write++);
39 }
40 else
41 {
42 WATCHPOINT_SET(ptr->io_wait_count.read++);
43 }
44
45 /*
46 ** We are going to block on write, but at least on Solaris we might block
47 ** on write if we haven't read anything from our input buffer..
48 ** Try to purge the input buffer if we don't do any flow control in the
49 ** application layer (just sending a lot of data etc)
50 ** The test is moved down in the purge function to avoid duplication of
51 ** the test.
52 */
53 if (read_or_write == MEM_WRITE)
54 {
55 memcached_return_t rc= memcached_purge(ptr);
56 if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_STORED)
57 return MEMCACHED_FAILURE;
58 }
59
60 int timeout= ptr->root->poll_timeout;
61 if (ptr->root->flags.no_block == false)
62 timeout= -1;
63
64 size_t loop_max= 5;
65 while (--loop_max) // While loop is for ERESTART or EINTR
66 {
67 error= poll(&fds, 1, timeout);
68
69 switch (error)
70 {
71 case 1: // Success!
72 WATCHPOINT_IF_LABELED_NUMBER(read_or_write && loop_max < 4, "read() times we had to loop, decremented down from 5", loop_max);
73 WATCHPOINT_IF_LABELED_NUMBER(!read_or_write && loop_max < 4, "write() times we had to loop, decremented down from 5", loop_max);
74
75 return MEMCACHED_SUCCESS;
76 case 0: // Timeout occured, we let the while() loop do its thing.
77 return MEMCACHED_TIMEOUT;
78 default:
79 WATCHPOINT_ERRNO(errno);
80 switch (errno)
81 {
82 #ifdef TARGET_OS_LINUX
83 case ERESTART:
84 #endif
85 case EINTR:
86 break;
87 default:
88 if (fds.revents & POLLERR)
89 {
90 int err;
91 socklen_t len= sizeof (err);
92 (void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len);
93 ptr->cached_errno= (err == 0) ? errno : err;
94 }
95 else
96 {
97 ptr->cached_errno= errno;
98 }
99 memcached_quit_server(ptr, true);
100
101 return MEMCACHED_FAILURE;
102 }
103 }
104 }
105
106 /* Imposssible for anything other then -1 */
107 WATCHPOINT_ASSERT(error == -1);
108 ptr->cached_errno= errno;
109 memcached_quit_server(ptr, true);
110
111 return MEMCACHED_FAILURE;
112 }
113
114 /**
115 * Try to fill the input buffer for a server with as much
116 * data as possible.
117 *
118 * @param ptr the server to pack
119 */
120 static bool repack_input_buffer(memcached_server_write_instance_st ptr)
121 {
122 if (ptr->read_ptr != ptr->read_buffer)
123 {
124 /* Move all of the data to the beginning of the buffer so
125 ** that we can fit more data into the buffer...
126 */
127 memmove(ptr->read_buffer, ptr->read_ptr, ptr->read_buffer_length);
128 ptr->read_ptr= ptr->read_buffer;
129 ptr->read_data_length= ptr->read_buffer_length;
130 }
131
132 /* There is room in the buffer, try to fill it! */
133 if (ptr->read_buffer_length != MEMCACHED_MAX_BUFFER)
134 {
135 /* Just try a single read to grab what's available */
136 ssize_t nr= read(ptr->fd,
137 ptr->read_ptr + ptr->read_data_length,
138 MEMCACHED_MAX_BUFFER - ptr->read_data_length);
139
140 if (nr > 0)
141 {
142 ptr->read_data_length+= (size_t)nr;
143 ptr->read_buffer_length+= (size_t)nr;
144 return true;
145 }
146 }
147 return false;
148 }
149
150 /**
151 * If the we have callbacks connected to this server structure
152 * we may start process the input queue and fire the callbacks
153 * for the incomming messages. This function is _only_ called
154 * when the input buffer is full, so that we _know_ that we have
155 * at least _one_ message to process.
156 *
157 * @param ptr the server to star processing iput messages for
158 * @return true if we processed anything, false otherwise
159 */
160 static bool process_input_buffer(memcached_server_write_instance_st ptr)
161 {
162 /*
163 ** We might be able to process some of the response messages if we
164 ** have a callback set up
165 */
166 if (ptr->root->callbacks != NULL && ptr->root->flags.use_udp == false)
167 {
168 /*
169 * We might have responses... try to read them out and fire
170 * callbacks
171 */
172 memcached_callback_st cb= *ptr->root->callbacks;
173
174 memcached_set_processing_input((memcached_st *)ptr->root, true);
175
176 char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
177 memcached_return_t error;
178 memcached_st *root= (memcached_st *)ptr->root;
179 error= memcached_response(ptr, buffer, sizeof(buffer),
180 &root->result);
181
182 memcached_set_processing_input(root, false);
183
184 if (error == MEMCACHED_SUCCESS)
185 {
186 for (unsigned int x= 0; x < cb.number_of_callback; x++)
187 {
188 error= (*cb.callback[x])(ptr->root, &root->result, cb.context);
189 if (error != MEMCACHED_SUCCESS)
190 break;
191 }
192
193 /* @todo what should I do with the error message??? */
194 }
195 /* @todo what should I do with other error messages?? */
196 return true;
197 }
198
199 return false;
200 }
201
202 static inline void memcached_io_cork_push(memcached_server_st *ptr)
203 {
204 (void)ptr;
205 #ifdef CORK
206 if (ptr->root->flags.cork == false || ptr->state.is_corked)
207 return;
208
209 int enable= 1;
210 int err= setsockopt(ptr->fd, IPPROTO_TCP, CORK,
211 &enable, (socklen_t)sizeof(int));
212 if (! err)
213 ptr->state.is_corked= true;
214
215 WATCHPOINT_ASSERT(ptr->state.is_corked == true);
216 #endif
217 }
218
219 static inline void memcached_io_cork_pop(memcached_server_st *ptr)
220 {
221 (void)ptr;
222 #ifdef CORK
223 if (ptr->root->flags.cork == false || ptr->state.is_corked == false)
224 return;
225
226 int enable= 0;
227 int err= setsockopt(ptr->fd, IPPROTO_TCP, CORK,
228 &enable, (socklen_t)sizeof(int));
229 if (! err)
230 ptr->state.is_corked= false;
231
232 WATCHPOINT_ASSERT(ptr->state.is_corked == false);
233 #endif
234 }
235
236 #if 0 // Dead code, this should be removed.
237 void memcached_io_preread(memcached_st *ptr)
238 {
239 unsigned int x;
240
241 return;
242
243 for (x= 0; x < memcached_server_count(ptr); x++)
244 {
245 if (memcached_server_response_count(ptr, x) &&
246 ptr->hosts[x].read_data_length < MEMCACHED_MAX_BUFFER )
247 {
248 size_t data_read;
249
250 data_read= read(ptr->hosts[x].fd,
251 ptr->hosts[x].read_ptr + ptr->hosts[x].read_data_length,
252 MEMCACHED_MAX_BUFFER - ptr->hosts[x].read_data_length);
253 if (data_read == -1)
254 continue;
255
256 ptr->hosts[x].read_buffer_length+= data_read;
257 ptr->hosts[x].read_data_length+= data_read;
258 }
259 }
260 }
261 #endif
262
263 memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr,
264 void *buffer, size_t length, ssize_t *nread)
265 {
266 char *buffer_ptr;
267
268 buffer_ptr= buffer;
269
270 while (length)
271 {
272 if (!ptr->read_buffer_length)
273 {
274 ssize_t data_read;
275
276 while (1)
277 {
278 data_read= read(ptr->fd, ptr->read_buffer, MEMCACHED_MAX_BUFFER);
279 if (data_read > 0)
280 {
281 break;
282 }
283 else if (data_read == -1)
284 {
285 ptr->cached_errno= errno;
286 memcached_return_t rc= MEMCACHED_ERRNO;
287 switch (errno)
288 {
289 case EAGAIN:
290 case EINTR:
291 #ifdef TARGET_OS_LINUX
292 case ERESTART:
293 #endif
294 if ((rc= io_wait(ptr, MEM_READ)) == MEMCACHED_SUCCESS)
295 continue;
296 /* fall through */
297
298 default:
299 {
300 memcached_quit_server(ptr, true);
301 *nread= -1;
302 return rc;
303 }
304 }
305 }
306 else
307 {
308 /*
309 EOF. Any data received so far is incomplete
310 so discard it. This always reads by byte in case of TCP
311 and protocol enforcement happens at memcached_response()
312 looking for '\n'. We do not care for UDB which requests 8 bytes
313 at once. Generally, this means that connection went away. Since
314 for blocking I/O we do not return 0 and for non-blocking case
315 it will return EGAIN if data is not immediatly available.
316 */
317 WATCHPOINT_STRING("We had a zero length read()");
318 memcached_quit_server(ptr, true);
319 *nread= -1;
320 return MEMCACHED_UNKNOWN_READ_FAILURE;
321 }
322 }
323
324 ptr->io_bytes_sent = 0;
325 ptr->read_data_length= (size_t) data_read;
326 ptr->read_buffer_length= (size_t) data_read;
327 ptr->read_ptr= ptr->read_buffer;
328 }
329
330 if (length > 1)
331 {
332 size_t difference;
333
334 difference= (length > ptr->read_buffer_length) ? ptr->read_buffer_length : length;
335
336 memcpy(buffer_ptr, ptr->read_ptr, difference);
337 length -= difference;
338 ptr->read_ptr+= difference;
339 ptr->read_buffer_length-= difference;
340 buffer_ptr+= difference;
341 }
342 else
343 {
344 *buffer_ptr= *ptr->read_ptr;
345 ptr->read_ptr++;
346 ptr->read_buffer_length--;
347 buffer_ptr++;
348 break;
349 }
350 }
351
352 ptr->server_failure_counter= 0;
353 *nread = (ssize_t)(buffer_ptr - (char*)buffer);
354 return MEMCACHED_SUCCESS;
355 }
356
357 static ssize_t _io_write(memcached_server_write_instance_st ptr,
358 const void *buffer, size_t length, bool with_flush)
359 {
360 size_t original_length;
361 const char* buffer_ptr;
362
363 WATCHPOINT_ASSERT(ptr->fd != -1);
364
365 original_length= length;
366 buffer_ptr= buffer;
367
368 /* more writable data is coming if a flush isn't required, so delay send */
369 if (! with_flush)
370 {
371 memcached_io_cork_push(ptr);
372 }
373
374 while (length)
375 {
376 char *write_ptr;
377 size_t should_write;
378 size_t buffer_end;
379
380 if (ptr->type == MEMCACHED_CONNECTION_UDP)
381 {
382 //UDP does not support partial writes
383 buffer_end= MAX_UDP_DATAGRAM_LENGTH;
384 should_write= length;
385 if (ptr->write_buffer_offset + should_write > buffer_end)
386 return -1;
387 }
388 else
389 {
390 buffer_end= MEMCACHED_MAX_BUFFER;
391 should_write= buffer_end - ptr->write_buffer_offset;
392 should_write= (should_write < length) ? should_write : length;
393 }
394
395 write_ptr= ptr->write_buffer + ptr->write_buffer_offset;
396 memcpy(write_ptr, buffer_ptr, should_write);
397 ptr->write_buffer_offset+= should_write;
398 buffer_ptr+= should_write;
399 length-= should_write;
400
401 if (ptr->write_buffer_offset == buffer_end && ptr->type != MEMCACHED_CONNECTION_UDP)
402 {
403 memcached_return_t rc;
404 ssize_t sent_length;
405
406 WATCHPOINT_ASSERT(ptr->fd != -1);
407 sent_length= io_flush(ptr, &rc);
408 if (sent_length == -1)
409 return -1;
410
411 /* If io_flush calls memcached_purge, sent_length may be 0 */
412 unlikely (sent_length != 0)
413 {
414 WATCHPOINT_ASSERT(sent_length == (ssize_t)buffer_end);
415 }
416 }
417 }
418
419 if (with_flush)
420 {
421 memcached_return_t rc;
422 WATCHPOINT_ASSERT(ptr->fd != -1);
423 if (io_flush(ptr, &rc) == -1)
424 {
425 return -1;
426 }
427
428 memcached_io_cork_pop(ptr);
429 }
430
431 return (ssize_t) original_length;
432 }
433
434 ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
435 const void *buffer, size_t length, bool with_flush)
436 {
437 return _io_write(ptr, buffer, length, with_flush);
438 }
439
440 ssize_t memcached_io_writev(memcached_server_write_instance_st ptr,
441 const struct __write_vector_st *vector,
442 size_t number_of, bool with_flush)
443 {
444 ssize_t total= 0;
445
446 for (size_t x= 0; x < number_of; x++, vector++)
447 {
448 ssize_t returnable;
449
450 if ((returnable= _io_write(ptr, vector->buffer, vector->length, false)) == -1)
451 {
452 return -1;
453 }
454 total+= returnable;
455 }
456
457 if (with_flush)
458 {
459 if (memcached_io_write(ptr, NULL, 0, true) == -1)
460 {
461 return -1;
462 }
463 }
464
465 return total;
466 }
467
468
469 memcached_return_t memcached_io_close(memcached_server_write_instance_st ptr)
470 {
471 if (ptr->fd == -1)
472 {
473 return MEMCACHED_SUCCESS;
474 }
475
476 /* in case of death shutdown to avoid blocking at close() */
477 if (shutdown(ptr->fd, SHUT_RDWR) == -1 && errno != ENOTCONN)
478 {
479 WATCHPOINT_NUMBER(ptr->fd);
480 WATCHPOINT_ERRNO(errno);
481 WATCHPOINT_ASSERT(errno);
482 }
483
484 if (close(ptr->fd) == -1)
485 {
486 WATCHPOINT_ERRNO(errno);
487 }
488
489 return MEMCACHED_SUCCESS;
490 }
491
492 memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st *memc)
493 {
494 #define MAX_SERVERS_TO_POLL 100
495 struct pollfd fds[MAX_SERVERS_TO_POLL];
496 unsigned int host_index= 0;
497
498 for (uint32_t x= 0;
499 x< memcached_server_count(memc) && host_index < MAX_SERVERS_TO_POLL;
500 ++x)
501 {
502 memcached_server_write_instance_st instance=
503 memcached_server_instance_fetch(memc, x);
504
505 if (instance->read_buffer_length > 0) /* I have data in the buffer */
506 return instance;
507
508 if (memcached_server_response_count(instance) > 0)
509 {
510 fds[host_index].events = POLLIN;
511 fds[host_index].revents = 0;
512 fds[host_index].fd = instance->fd;
513 ++host_index;
514 }
515 }
516
517 if (host_index < 2)
518 {
519 /* We have 0 or 1 server with pending events.. */
520 for (uint32_t x= 0; x< memcached_server_count(memc); ++x)
521 {
522 memcached_server_write_instance_st instance=
523 memcached_server_instance_fetch(memc, x);
524
525 if (memcached_server_response_count(instance) > 0)
526 {
527 return instance;
528 }
529 }
530
531 return NULL;
532 }
533
534 int err= poll(fds, host_index, memc->poll_timeout);
535 switch (err) {
536 case -1:
537 memc->cached_errno = errno;
538 /* FALLTHROUGH */
539 case 0:
540 break;
541 default:
542 for (size_t x= 0; x < host_index; ++x)
543 {
544 if (fds[x].revents & POLLIN)
545 {
546 for (uint32_t y= 0; y < memcached_server_count(memc); ++y)
547 {
548 memcached_server_write_instance_st instance=
549 memcached_server_instance_fetch(memc, y);
550
551 if (instance->fd == fds[x].fd)
552 return instance;
553 }
554 }
555 }
556 }
557
558 return NULL;
559 }
560
561 static ssize_t io_flush(memcached_server_write_instance_st ptr,
562 memcached_return_t *error)
563 {
564 /*
565 ** We might want to purge the input buffer if we haven't consumed
566 ** any output yet... The test for the limits is the purge is inline
567 ** in the purge function to avoid duplicating the logic..
568 */
569 {
570 memcached_return_t rc;
571 WATCHPOINT_ASSERT(ptr->fd != -1);
572 rc= memcached_purge(ptr);
573
574 if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_STORED)
575 return -1;
576 }
577 ssize_t sent_length;
578 size_t return_length;
579 char *local_write_ptr= ptr->write_buffer;
580 size_t write_length= ptr->write_buffer_offset;
581
582 *error= MEMCACHED_SUCCESS;
583
584 WATCHPOINT_ASSERT(ptr->fd != -1);
585
586 // UDP Sanity check, make sure that we are not sending somthing too big
587 if (ptr->type == MEMCACHED_CONNECTION_UDP && write_length > MAX_UDP_DATAGRAM_LENGTH)
588 return -1;
589
590 if (ptr->write_buffer_offset == 0 || (ptr->type == MEMCACHED_CONNECTION_UDP
591 && ptr->write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH))
592 return 0;
593
594 /* Looking for memory overflows */
595 #if defined(DEBUG)
596 if (write_length == MEMCACHED_MAX_BUFFER)
597 WATCHPOINT_ASSERT(ptr->write_buffer == local_write_ptr);
598 WATCHPOINT_ASSERT((ptr->write_buffer + MEMCACHED_MAX_BUFFER) >= (local_write_ptr + write_length));
599 #endif
600
601 return_length= 0;
602 while (write_length)
603 {
604 WATCHPOINT_ASSERT(ptr->fd != -1);
605 WATCHPOINT_ASSERT(write_length > 0);
606 sent_length= 0;
607 if (ptr->type == MEMCACHED_CONNECTION_UDP)
608 increment_udp_message_id(ptr);
609 sent_length= write(ptr->fd, local_write_ptr, write_length);
610
611 if (sent_length == -1)
612 {
613 ptr->cached_errno= errno;
614 WATCHPOINT_ERRNO(errno);
615 WATCHPOINT_NUMBER(errno);
616 switch (errno)
617 {
618 case ENOBUFS:
619 continue;
620 case EAGAIN:
621 {
622 /*
623 * We may be blocked on write because the input buffer
624 * is full. Let's check if we have room in our input
625 * buffer for more data and retry the write before
626 * waiting..
627 */
628 if (repack_input_buffer(ptr) ||
629 process_input_buffer(ptr))
630 continue;
631
632 memcached_return_t rc;
633 rc= io_wait(ptr, MEM_WRITE);
634
635 if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_TIMEOUT)
636 continue;
637
638 memcached_quit_server(ptr, true);
639 return -1;
640 }
641 default:
642 memcached_quit_server(ptr, true);
643 *error= MEMCACHED_ERRNO;
644 return -1;
645 }
646 }
647
648 if (ptr->type == MEMCACHED_CONNECTION_UDP &&
649 (size_t)sent_length != write_length)
650 {
651 memcached_quit_server(ptr, true);
652 return -1;
653 }
654
655 ptr->io_bytes_sent += (uint32_t) sent_length;
656
657 local_write_ptr+= sent_length;
658 write_length-= (uint32_t) sent_length;
659 return_length+= (uint32_t) sent_length;
660 }
661
662 WATCHPOINT_ASSERT(write_length == 0);
663 // Need to study this assert() WATCHPOINT_ASSERT(return_length ==
664 // ptr->write_buffer_offset);
665
666 // if we are a udp server, the begining of the buffer is reserverd for
667 // the upd frame header
668 if (ptr->type == MEMCACHED_CONNECTION_UDP)
669 ptr->write_buffer_offset= UDP_DATAGRAM_HEADER_LENGTH;
670 else
671 ptr->write_buffer_offset= 0;
672
673 return (ssize_t) return_length;
674 }
675
676 /*
677 Eventually we will just kill off the server with the problem.
678 */
679 void memcached_io_reset(memcached_server_write_instance_st ptr)
680 {
681 memcached_quit_server(ptr, true);
682 }
683
684 /**
685 * Read a given number of bytes from the server and place it into a specific
686 * buffer. Reset the IO channel on this server if an error occurs.
687 */
688 memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr,
689 void *dta,
690 size_t size)
691 {
692 size_t offset= 0;
693 char *data= dta;
694
695 while (offset < size)
696 {
697 ssize_t nread;
698 memcached_return_t rc= memcached_io_read(ptr, data + offset, size - offset,
699 &nread);
700 if (rc != MEMCACHED_SUCCESS)
701 return rc;
702
703 offset+= (size_t) nread;
704 }
705
706 return MEMCACHED_SUCCESS;
707 }
708
709 memcached_return_t memcached_io_readline(memcached_server_write_instance_st ptr,
710 char *buffer_ptr,
711 size_t size)
712 {
713 bool line_complete= false;
714 size_t total_nr= 0;
715
716 while (!line_complete)
717 {
718 if (ptr->read_buffer_length == 0)
719 {
720 /*
721 * We don't have any data in the buffer, so let's fill the read
722 * buffer. Call the standard read function to avoid duplicating
723 * the logic.
724 */
725 ssize_t nread;
726 memcached_return_t rc= memcached_io_read(ptr, buffer_ptr, 1, &nread);
727 if (rc != MEMCACHED_SUCCESS)
728 return rc;
729
730 if (*buffer_ptr == '\n')
731 line_complete= true;
732
733 ++buffer_ptr;
734 ++total_nr;
735 }
736
737 /* Now let's look in the buffer and copy as we go! */
738 while (ptr->read_buffer_length && total_nr < size && !line_complete)
739 {
740 *buffer_ptr = *ptr->read_ptr;
741 if (*buffer_ptr == '\n')
742 line_complete = true;
743 --ptr->read_buffer_length;
744 ++ptr->read_ptr;
745 ++total_nr;
746 ++buffer_ptr;
747 }
748
749 if (total_nr == size)
750 return MEMCACHED_PROTOCOL_ERROR;
751 }
752
753 return MEMCACHED_SUCCESS;
754 }
755
756 /*
757 * The udp request id consists of two seperate sections
758 * 1) The thread id
759 * 2) The message number
760 * The thread id should only be set when the memcached_st struct is created
761 * and should not be changed.
762 *
763 * The message num is incremented for each new message we send, this function
764 * extracts the message number from message_id, increments it and then
765 * writes the new value back into the header
766 */
767 static void increment_udp_message_id(memcached_server_write_instance_st ptr)
768 {
769 struct udp_datagram_header_st *header= (struct udp_datagram_header_st *)ptr->write_buffer;
770 uint16_t cur_req= get_udp_datagram_request_id(header);
771 int msg_num= get_msg_num_from_request_id(cur_req);
772 int thread_id= get_thread_id_from_request_id(cur_req);
773
774 if (((++msg_num) & UDP_REQUEST_ID_THREAD_MASK) != 0)
775 msg_num= 0;
776
777 header->request_id= htons((uint16_t) (thread_id | msg_num));
778 }
779
780 memcached_return_t memcached_io_init_udp_header(memcached_server_write_instance_st ptr, uint16_t thread_id)
781 {
782 if (thread_id > UDP_REQUEST_ID_MAX_THREAD_ID)
783 return MEMCACHED_FAILURE;
784
785 struct udp_datagram_header_st *header= (struct udp_datagram_header_st *)ptr->write_buffer;
786 header->request_id= htons((uint16_t) (generate_udp_request_thread_id(thread_id)));
787 header->num_datagrams= htons(1);
788 header->sequence_number= htons(0);
789
790 return MEMCACHED_SUCCESS;
791 }