6c58e69cd902c56f2dde262213b19415350db281
[m6w6/libmemcached] / src / libmemcached / flush_buffers.cc
1 /*
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
14 */
15
16 #include "libmemcached/common.h"
17 #include "p9y/socket.hpp"
18
19 memcached_return_t memcached_flush_buffers(memcached_st *shell) {
20 Memcached *memc = memcached2Memcached(shell);
21 if (memc) {
22 memcached_return_t ret = MEMCACHED_SUCCESS;
23
24 for (uint32_t x = 0; x < memcached_server_count(memc); ++x) {
25 memcached_instance_st *instance = memcached_instance_fetch(memc, x);
26
27 if (instance->write_buffer_offset) {
28 if (instance->fd == INVALID_SOCKET
29 and (ret = memcached_connect(instance)) != MEMCACHED_SUCCESS) {
30 WATCHPOINT_ERROR(ret);
31 return ret;
32 }
33
34 if (memcached_io_write(instance) == false) {
35 ret = MEMCACHED_SOME_ERRORS;
36 }
37 }
38 }
39
40 return ret;
41 }
42
43 return MEMCACHED_INVALID_ARGUMENTS;
44 }