3 static memcached_return_t
memcached_flush_binary(memcached_st
*ptr
,
5 static memcached_return_t
memcached_flush_textual(memcached_st
*ptr
,
8 memcached_return_t
memcached_flush(memcached_st
*ptr
, time_t expiration
)
10 memcached_return_t rc
;
11 if ((rc
= initialize_query(ptr
)) != MEMCACHED_SUCCESS
)
16 LIBMEMCACHED_MEMCACHED_FLUSH_START();
17 if (ptr
->flags
.binary_protocol
)
18 rc
= memcached_flush_binary(ptr
, expiration
);
20 rc
= memcached_flush_textual(ptr
, expiration
);
21 LIBMEMCACHED_MEMCACHED_FLUSH_END();
25 static memcached_return_t
memcached_flush_textual(memcached_st
*ptr
,
28 unlikely (memcached_server_count(ptr
) == 0)
29 return MEMCACHED_NO_SERVERS
;
31 for (unsigned int x
= 0; x
< memcached_server_count(ptr
); x
++)
33 memcached_return_t rc
;
34 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
36 bool no_reply
= ptr
->flags
.no_reply
;
37 memcached_server_write_instance_st instance
=
38 memcached_server_instance_fetch(ptr
, x
);
43 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
44 "flush_all %llu%s\r\n",
45 (unsigned long long)expiration
, no_reply
? " noreply" : "");
49 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
50 "flush_all%s\r\n", no_reply
? " noreply" : "");
53 if (send_length
>= MEMCACHED_DEFAULT_COMMAND_SIZE
|| send_length
< 0)
55 return MEMCACHED_FAILURE
;
58 rc
= memcached_do(instance
, buffer
, (size_t)send_length
, true);
60 if (rc
== MEMCACHED_SUCCESS
&& !no_reply
)
61 (void)memcached_response(instance
, buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
64 return MEMCACHED_SUCCESS
;
67 static memcached_return_t
memcached_flush_binary(memcached_st
*ptr
,
70 protocol_binary_request_flush request
= {.bytes
= {0}};
72 unlikely (memcached_server_count(ptr
) == 0)
73 return MEMCACHED_NO_SERVERS
;
75 request
.message
.header
.request
.magic
= (uint8_t)PROTOCOL_BINARY_REQ
;
76 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_FLUSH
;
77 request
.message
.header
.request
.extlen
= 4;
78 request
.message
.header
.request
.datatype
= PROTOCOL_BINARY_RAW_BYTES
;
79 request
.message
.header
.request
.bodylen
= htonl(request
.message
.header
.request
.extlen
);
80 request
.message
.body
.expiration
= htonl((uint32_t) expiration
);
82 for (uint32_t x
= 0; x
< memcached_server_count(ptr
); x
++)
84 memcached_server_write_instance_st instance
=
85 memcached_server_instance_fetch(ptr
, x
);
87 if (ptr
->flags
.no_reply
)
89 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_FLUSHQ
;
93 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_FLUSH
;
96 if (memcached_do(instance
, request
.bytes
, sizeof(request
.bytes
), true) != MEMCACHED_SUCCESS
)
98 memcached_io_reset(instance
);
99 return MEMCACHED_WRITE_FAILURE
;
103 for (uint32_t x
= 0; x
< memcached_server_count(ptr
); x
++)
105 memcached_server_write_instance_st instance
=
106 memcached_server_instance_fetch(ptr
, x
);
108 if (memcached_server_response_count(instance
) > 0)
109 (void)memcached_response(instance
, NULL
, 0, NULL
);
112 return MEMCACHED_SUCCESS
;