#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
+#include <sys/socket.h>
#include <glib.h>
s_info.processing_event_callback &= ~PROCESSING_DISCONNECTION;
}
+static int validate_handle(int fd)
+{
+ int error;
+ socklen_t len;
+
+ len = sizeof(error);
+ if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
+ ErrPrint("getsockopt: %s\n", strerror(errno));
+ return 0;
+ }
+
+ return !(error == EBADF);
+}
+
static gboolean client_cb(GIOChannel *src, GIOCondition cond, gpointer data)
{
int client_fd;
return FALSE;
}
- return TRUE;
+ /* Check whether the socket FD is closed or not */
+ return validate_handle(client_fd) ? TRUE : FALSE;
}
static gboolean accept_cb(GIOChannel *src, GIOCondition cond, gpointer cbdata)
g_io_channel_unref(gio);
invoke_con_cb_list(client_fd);
- return TRUE;
+ return validate_handle(socket_fd) ? TRUE : FALSE;
}
EAPI int com_core_server_create(const char *addr, int is_sync, int (*service_cb)(int fd, void *data), void *data)
return NULL;
}
+static inline void recreate_recv_ctx(struct recv_ctx *ctx)
+{
+ if (ctx->packet) {
+ packet_destroy(ctx->packet);
+ ctx->packet = NULL;
+ }
+ ctx->state = RECV_STATE_INIT;
+ ctx->offset = 0;
+ ctx->pid = (pid_t)-1;
+ // ctx->inuse
+ // ctx->handle
+ // ctx->timeout
+}
+
static inline void destroy_recv_ctx(struct recv_ctx *ctx)
{
struct dlist *l;
if (receive->state == RECV_STATE_READY) {
ret = packet_ready(handle, receive, data);
if (ret == 0) {
- destroy_recv_ctx(receive);
+ /*!
+ * If ret is negative value, the receive context will be destroyed from disconnected callback
+ */
+ recreate_recv_ctx(receive);
}
/*!
* if ret is negative value, disconnected_cb will be called after this function