From 1a27eb8813e53b241644074a53d029286e1b35d6 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Thu, 29 Dec 2011 13:04:28 +0000 Subject: [PATCH] more formatting improvements SVN revision: 66632 --- legacy/eet/src/lib/eet_connection.c | 65 ++++++++++------------------- 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/legacy/eet/src/lib/eet_connection.c b/legacy/eet/src/lib/eet_connection.c index a11816ffa8..0aaa566c33 100644 --- a/legacy/eet/src/lib/eet_connection.c +++ b/legacy/eet/src/lib/eet_connection.c @@ -35,6 +35,7 @@ void *alloca(size_t); #include "Eet.h" #include "Eet_private.h" +#define MAX_MSG_SIZE (64 * 1024) #define MAGIC_EET_DATA_PACKET 0x4270ACE1 struct _Eet_Connection @@ -57,17 +58,13 @@ eet_connection_new(Eet_Read_Cb *eet_read_cb, { Eet_Connection *conn; - if (!eet_read_cb || !eet_write_cb) - return NULL; + if ((!eet_read_cb) || (!eet_write_cb)) return NULL; conn = calloc(1, sizeof (Eet_Connection)); - if (!conn) - return NULL; - + if (!conn) return NULL; conn->eet_read_cb = eet_read_cb; conn->eet_write_cb = eet_write_cb; conn->user_data = (void *)user_data; - return conn; } @@ -86,34 +83,34 @@ eet_connection_received(Eet_Connection *conn, const int *msg; size_t packet_size; - if (size < sizeof (int) * 2) break; + if (size < (sizeof(int) * 2)) break; msg = data; /* Check the magic */ if (ntohl(msg[0]) != MAGIC_EET_DATA_PACKET) break; packet_size = ntohl(msg[1]); - /* Message should always be under 64K */ - if (packet_size > 64 * 1024) break; + /* Message should always be under MAX_MSG_SIZE */ + if (packet_size > MAX_MSG_SIZE) break; data = (void *)(msg + 2); - size -= sizeof (int) * 2; + size -= sizeof(int) * 2; if ((size_t)packet_size <= size) { /* Not a partial receive, go the quick way. */ if (!conn->eet_read_cb(data, packet_size, conn->user_data)) break; - - data = (void *)((char *)data + packet_size); - size -= packet_size; - conn->received = 0; - continue; + + data = (void *)((char *)data + packet_size); + size -= packet_size; + conn->received = 0; + continue; } conn->size = packet_size; if (conn->allocated < conn->size) { void *tmp; - + tmp = realloc(conn->buffer, conn->size); if (!tmp) break; conn->buffer = tmp; @@ -138,7 +135,6 @@ eet_connection_received(Eet_Connection *conn, data_size = conn->size; conn->size = 0; conn->received = 0; - /* Completed a packet. */ if (!conn->eet_read_cb(conn->buffer, data_size, conn->user_data)) { @@ -160,18 +156,14 @@ _eet_connection_raw_send(Eet_Connection *conn, { int *message; - /* Message should never be above 64K */ - if (data_size > 64 * 1024) - return EINA_FALSE; - - message = alloca(data_size + sizeof (int) * 2); + /* Message should always be under MAX_MSG_SIZE */ + if (data_size > MAX_MSG_SIZE) return EINA_FALSE; + message = alloca(data_size + (sizeof(int) * 2)); message[0] = htonl(MAGIC_EET_DATA_PACKET); message[1] = htonl(data_size); - memcpy(message + 2, data, data_size); - conn->eet_write_cb(message, - data_size + sizeof (int) * 2, + data_size + (sizeof(int) * 2), conn->user_data); return EINA_TRUE; } @@ -190,12 +182,8 @@ eet_connection_send(Eet_Connection *conn, data_in, cipher_key, &data_size); - if (!flat_data) - return EINA_FALSE; - - if (_eet_connection_raw_send(conn, flat_data, data_size)) - ret = EINA_TRUE; - + if (!flat_data) return EINA_FALSE; + if (_eet_connection_raw_send(conn, flat_data, data_size)) ret = EINA_TRUE; free(flat_data); return ret; } @@ -210,12 +198,9 @@ eet_connection_node_send(Eet_Connection *conn, Eina_Bool ret = EINA_FALSE; data = eet_data_node_encode_cipher(node, cipher_key, &data_size); - if (!data) - return EINA_FALSE; - + if (!data) return EINA_FALSE; if (_eet_connection_raw_send(conn, data, data_size)) ret = EINA_TRUE; - free(data); return ret; } @@ -226,17 +211,11 @@ eet_connection_close(Eet_Connection *conn, { void *user_data; - if (!conn) - return NULL; - - if (on_going) - *on_going = conn->received == 0 ? EINA_FALSE : EINA_TRUE; - + if (!conn) return NULL; + if (on_going) *on_going = conn->received == 0 ? EINA_FALSE : EINA_TRUE; user_data = conn->user_data; - free(conn->buffer); free(conn); - return user_data; }