3 static memcached_return
memcached_flush_binary(memcached_st
*ptr
,
5 static memcached_return
memcached_flush_textual(memcached_st
*ptr
,
8 memcached_return
memcached_flush(memcached_st
*ptr
, time_t expiration
)
12 LIBMEMCACHED_MEMCACHED_FLUSH_START();
13 if (ptr
->flags
& MEM_BINARY_PROTOCOL
)
14 rc
= memcached_flush_binary(ptr
, expiration
);
16 rc
= memcached_flush_textual(ptr
, expiration
);
17 LIBMEMCACHED_MEMCACHED_FLUSH_END();
21 static memcached_return
memcached_flush_textual(memcached_st
*ptr
,
27 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
29 unlikely (ptr
->number_of_hosts
== 0)
30 return MEMCACHED_NO_SERVERS
;
32 for (x
= 0; x
< ptr
->number_of_hosts
; x
++)
34 bool no_reply
= (ptr
->flags
& MEM_NOREPLY
);
36 send_length
= (size_t) snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
37 "flush_all %llu%s\r\n",
38 (unsigned long long)expiration
, no_reply
? " noreply" : "");
40 send_length
= (size_t) snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
41 "flush_all%s\r\n", no_reply
? " noreply" : "");
43 rc
= memcached_do(&ptr
->hosts
[x
], buffer
, send_length
, 1);
45 if (rc
== MEMCACHED_SUCCESS
&& !no_reply
)
46 (void)memcached_response(&ptr
->hosts
[x
], buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
49 return MEMCACHED_SUCCESS
;
52 static memcached_return
memcached_flush_binary(memcached_st
*ptr
,
56 protocol_binary_request_flush request
= {.bytes
= {0}};
58 unlikely (ptr
->number_of_hosts
== 0)
59 return MEMCACHED_NO_SERVERS
;
61 request
.message
.header
.request
.magic
= (uint8_t)PROTOCOL_BINARY_REQ
;
62 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_FLUSH
;
63 request
.message
.header
.request
.extlen
= 4;
64 request
.message
.header
.request
.datatype
= PROTOCOL_BINARY_RAW_BYTES
;
65 request
.message
.header
.request
.bodylen
= htonl(request
.message
.header
.request
.extlen
);
66 request
.message
.body
.expiration
= htonl((uint32_t) expiration
);
68 for (x
= 0; x
< ptr
->number_of_hosts
; x
++)
70 if (ptr
->flags
& MEM_NOREPLY
)
71 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_FLUSHQ
;
73 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_FLUSH
;
74 if (memcached_do(&ptr
->hosts
[x
], request
.bytes
,
75 sizeof(request
.bytes
), 1) != MEMCACHED_SUCCESS
)
77 memcached_io_reset(&ptr
->hosts
[x
]);
78 return MEMCACHED_WRITE_FAILURE
;
82 for (x
= 0; x
< ptr
->number_of_hosts
; x
++)
84 if (memcached_server_response_count(&ptr
->hosts
[x
]) > 0)
85 (void)memcached_response(&ptr
->hosts
[x
], NULL
, 0, NULL
);
88 return MEMCACHED_SUCCESS
;