Merge pull request #140 from hussainnaqvee/patch-1
[awesomized/libmemcached] / src / libmemcachedprotocol / handler.c
index 885c798fa6edd113dddee77b5ac1161bd503fdca..ce77993b151344bd2e505c90a56ba874828fd103 100644 (file)
@@ -1,6 +1,6 @@
 /*
     +--------------------------------------------------------------------+
-    | libmemcached - C/C++ Client Library for memcached                  |
+    | libmemcached-awesome - C/C++ Client Library for memcached          |
     +--------------------------------------------------------------------+
     | Redistribution and use in source and binary forms, with or without |
     | modification, are permitted under the terms of the BSD license.    |
@@ -9,7 +9,7 @@
     | the terms online at: https://opensource.org/licenses/BSD-3-Clause  |
     +--------------------------------------------------------------------+
     | Copyright (c) 2006-2014 Brian Aker   https://datadifferential.com/ |
-    | Copyright (c) 2020 Michael Wallner   <mike@php.net>                |
+    | Copyright (c) 2020-2021 Michael Wallner        https://awesome.co/ |
     +--------------------------------------------------------------------+
 */
 
 #include <errno.h>
 #include <stdbool.h>
 #include <string.h>
-#include <strings.h>
+#if HAVE_STRINGS_H
+#  include <strings.h>
+#endif
 #include <ctype.h>
 #include <stdio.h>
 
-#include <sys/types.h>
-#include <sys/socket.h>
+#include "p9y/socket.hpp"
 
 /*
 ** **********************************************************************
@@ -82,7 +83,7 @@ static bool drain_output(struct memcached_protocol_client_st *client) {
   }
 
   /* Do we have pending data to send? */
-  while (client->output != NULL) {
+  while (client->output) {
     ssize_t len =
         client->root->send(client, client->sock, client->output->data + client->output->offset,
                            client->output->nbytes - client->output->offset);
@@ -238,7 +239,7 @@ static memcached_protocol_event_t determine_protocol(struct memcached_protocol_c
 */
 struct memcached_protocol_st *memcached_protocol_create_instance(void) {
   struct memcached_protocol_st *ret = calloc(1, sizeof(*ret));
-  if (ret != NULL) {
+  if (ret) {
     ret->recv = default_recv;
     ret->send = default_send;
     ret->drain = drain_output;
@@ -273,7 +274,7 @@ void memcached_protocol_destroy_instance(struct memcached_protocol_st *instance)
 struct memcached_protocol_client_st *
 memcached_protocol_create_client(struct memcached_protocol_st *instance, memcached_socket_t sock) {
   struct memcached_protocol_client_st *ret = calloc(1, sizeof(memcached_protocol_client_st));
-  if (ret != NULL) {
+  if (ret) {
     ret->root = instance;
     ret->sock = sock;
     ret->work = determine_protocol;