-static memcached_return_t io_wait(memcached_instance_st *instance, const short events) {
- /*
- ** We are going to block on write, but at least on Solaris we might block
- ** on write if we haven't read anything from our input buffer..
- ** Try to purge the input buffer if we don't do any flow control in the
- ** application layer (just sending a lot of data etc)
- ** The test is moved down in the purge function to avoid duplication of
- ** the test.
- */
- if (events & POLLOUT) {
- if (memcached_purge(instance) == false) {
- return MEMCACHED_FAILURE;
- }
+static memcached_return_t io_sock_err(memcached_instance_st *inst,
+ const char *reason_str, size_t reason_len) {
+ int err;
+ socklen_t len = sizeof(err);
+
+ if (getsockopt(inst->fd, SOL_SOCKET, SO_ERROR, (char *) &err, &len) == -1) {
+ return memcached_set_errno(*inst, errno, MEMCACHED_AT,
+ memcached_literal_param("getsockopt()"));
+ }
+
+ if (err) {
+ return memcached_set_errno(*inst, err, MEMCACHED_AT, reason_str, reason_len);