512fa2b7a429681419a061d330cf938ca248b013
[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
18 memcached_return_t memcached_flush_buffers(memcached_st *shell) {
19 Memcached *memc = memcached2Memcached(shell);
20 if (memc) {
21 memcached_return_t ret = MEMCACHED_SUCCESS;
22
23 for (uint32_t x = 0; x < memcached_server_count(memc); ++x) {
24 memcached_instance_st *instance = memcached_instance_fetch(memc, x);
25
26 if (instance->write_buffer_offset) {
27 if (instance->fd == INVALID_SOCKET
28 and (ret = memcached_connect(instance)) != MEMCACHED_SUCCESS) {
29 WATCHPOINT_ERROR(ret);
30 return ret;
31 }
32
33 if (memcached_io_write(instance) == false) {
34 ret = MEMCACHED_SOME_ERRORS;
35 }
36 }
37 }
38
39 return ret;
40 }
41
42 return MEMCACHED_INVALID_ARGUMENTS;
43 }