summaryrefslogtreecommitdiff
path: root/legacy/eet/src/lib/eet_connection.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2010-07-28 01:45:57 +0000
committerCarsten Haitzler <raster@rasterman.com>2010-07-28 01:45:57 +0000
commit926db95c5476a7e58ae30873227140b627fc292d (patch)
tree921fa2fb03c97910853287c1a15379175e845994 /legacy/eet/src/lib/eet_connection.c
parentba10bce4342f61992ceaf06dc6299639cac83a81 (diff)
testing uncrustify on eet. this shall be standard efl formatting from
now on. you may run indent on code and convert to your own formatting if you want.. but all code MUST be "uncrustified" before being cxommitted to svn or before generating patches. time to get the formatting monster under control. SVN revision: 50563
Diffstat (limited to 'legacy/eet/src/lib/eet_connection.c')
-rw-r--r--legacy/eet/src/lib/eet_connection.c199
1 files changed, 106 insertions, 93 deletions
diff --git a/legacy/eet/src/lib/eet_connection.c b/legacy/eet/src/lib/eet_connection.c
index 01e8f51135..fb41ff0d91 100644
--- a/legacy/eet/src/lib/eet_connection.c
+++ b/legacy/eet/src/lib/eet_connection.c
@@ -42,7 +42,8 @@ void *alloca (size_t);
42#define MAGIC_EET_DATA_PACKET 0x4270ACE1 42#define MAGIC_EET_DATA_PACKET 0x4270ACE1
43 43
44typedef struct _Eet_Message Eet_Message; 44typedef struct _Eet_Message Eet_Message;
45struct _Eet_Message { 45struct _Eet_Message
46{
46 int magic; 47 int magic;
47 int size; 48 int size;
48}; 49};
@@ -62,21 +63,21 @@ struct _Eet_Connection
62 63
63EAPI Eet_Connection * 64EAPI Eet_Connection *
64eet_connection_new(Eet_Read_Cb *eet_read_cb, 65eet_connection_new(Eet_Read_Cb *eet_read_cb,
65 Eet_Write_Cb *eet_write_cb, 66 Eet_Write_Cb *eet_write_cb,
66 const void *user_data) 67 const void *user_data)
67{ 68{
68 Eet_Connection *conn; 69 Eet_Connection *conn;
69 70
70 if (!eet_read_cb || !eet_write_cb) 71 if (!eet_read_cb || !eet_write_cb)
71 return NULL; 72 return NULL;
72 73
73 conn = calloc(1, sizeof (Eet_Connection)); 74 conn = calloc(1, sizeof (Eet_Connection));
74 if (!conn) 75 if (!conn)
75 return NULL; 76 return NULL;
76 77
77 conn->eet_read_cb = eet_read_cb; 78 conn->eet_read_cb = eet_read_cb;
78 conn->eet_write_cb = eet_write_cb; 79 conn->eet_write_cb = eet_write_cb;
79 conn->user_data = (void*) user_data; 80 conn->user_data = (void *)user_data;
80 81
81 return conn; 82 return conn;
82} 83}
@@ -85,83 +86,85 @@ EAPI int
85eet_connection_received(Eet_Connection *conn, const void *data, size_t size) 86eet_connection_received(Eet_Connection *conn, const void *data, size_t size)
86{ 87{
87 if (!conn || !data || !size) 88 if (!conn || !data || !size)
88 return size; 89 return size;
89 90
90 do { 91 do {
91 size_t copy_size; 92 size_t copy_size;
92 93
93 if (conn->size == 0) 94 if (conn->size == 0)
94 { 95 {
95 const Eet_Message *msg; 96 const Eet_Message *msg;
96 size_t packet_size; 97 size_t packet_size;
97 98
98 if (size < sizeof (Eet_Message)) 99 if (size < sizeof (Eet_Message))
99 break; 100 break;
100 101
101 msg = data; 102 msg = data;
102 /* Check the magic */ 103 /* Check the magic */
103 if (ntohl(msg->magic) != MAGIC_EET_DATA_PACKET) 104 if (ntohl(msg->magic) != MAGIC_EET_DATA_PACKET)
104 break; 105 break;
105 106
106 packet_size = ntohl(msg->size); 107 packet_size = ntohl(msg->size);
107 /* Message should always be under 64K */ 108 /* Message should always be under 64K */
108 if (packet_size > 64 * 1024) 109 if (packet_size > 64 * 1024)
109 break; 110 break;
110 111
111 data = (void*) (msg + 1); 112 data = (void *)(msg + 1);
112 size -= sizeof (msg); 113 size -= sizeof (msg);
113 if ((size_t) packet_size <= size) 114 if ((size_t)packet_size <= size)
114 { 115 {
115 /* Not a partial receive, go the quick way. */ 116 /* Not a partial receive, go the quick way. */
116 if (!conn->eet_read_cb(data, packet_size, conn->user_data)) 117 if (!conn->eet_read_cb(data, packet_size, conn->user_data))
117 break; 118 break;
118 119
119 data = (void*) ((char *) data + packet_size); 120 data = (void *)((char *)data + packet_size);
120 size -= packet_size; 121 size -= packet_size;
121 122
122 conn->received = 0; 123 conn->received = 0;
123 continue; 124 continue;
124 } 125 }
125 126
126 conn->size = packet_size; 127 conn->size = packet_size;
127 if (conn->allocated < conn->size) 128 if (conn->allocated < conn->size)
128 { 129 {
129 void *tmp; 130 void *tmp;
130 131
131 tmp = realloc(conn->buffer, conn->size); 132 tmp = realloc(conn->buffer, conn->size);
132 if (!tmp) 133 if (!tmp)
133 break; 134 break;
134 135
135 conn->buffer = tmp; 136 conn->buffer = tmp;
136 conn->allocated = conn->size; 137 conn->allocated = conn->size;
137 } 138 }
138 } 139 }
139 140
140 /* Partial receive */ 141 /* Partial receive */
141 copy_size = (conn->size - conn->received >= size) ? size : conn->size - conn->received; 142 copy_size =
142 memcpy((char*) conn->buffer + conn->received, data, copy_size); 143 (conn->size - conn->received >=
143 144 size) ? size : conn->size - conn->received;
144 conn->received += copy_size; 145 memcpy((char *)conn->buffer + conn->received, data, copy_size);
145 data = (void*)((char *) data + copy_size); 146
146 size -= copy_size; 147 conn->received += copy_size;
147 148 data = (void *)((char *)data + copy_size);
148 if (conn->received == conn->size) 149 size -= copy_size;
149 { 150
150 size_t data_size; 151 if (conn->received == conn->size)
151 152 {
152 data_size = conn->size; 153 size_t data_size;
153 conn->size = 0; 154
154 conn->received = 0; 155 data_size = conn->size;
155 156 conn->size = 0;
156 /* Completed a packet. */ 157 conn->received = 0;
157 if (!conn->eet_read_cb(conn->buffer, data_size, conn->user_data)) 158
158 { 159 /* Completed a packet. */
159 /* Something goes wrong. Stop now. */ 160 if (!conn->eet_read_cb(conn->buffer, data_size, conn->user_data))
160 size += data_size; 161 {
161 break; 162 /* Something goes wrong. Stop now. */
162 } 163 size += data_size;
163 } 164 break;
164 } while (size > 0); 165 }
166 }
167 } while (size > 0);
165 168
166 return size; 169 return size;
167} 170}
@@ -173,38 +176,48 @@ _eet_connection_raw_send(Eet_Connection *conn, void *data, int data_size)
173 176
174 /* Message should never be above 64K */ 177 /* Message should never be above 64K */
175 if (data_size > 64 * 1024) 178 if (data_size > 64 * 1024)
176 return EINA_FALSE; 179 return EINA_FALSE;
177 180
178 message = alloca(data_size + sizeof (Eet_Message)); 181 message = alloca(data_size + sizeof (Eet_Message));
179 message->magic = htonl(MAGIC_EET_DATA_PACKET); 182 message->magic = htonl(MAGIC_EET_DATA_PACKET);
180 message->size = htonl(data_size); 183 message->size = htonl(data_size);
181 184
182 memcpy(message + 1, data, data_size); 185 memcpy(message + 1, data, data_size);
183 186
184 conn->eet_write_cb(message, data_size + sizeof (Eet_Message), conn->user_data); 187 conn->eet_write_cb(message,
188 data_size + sizeof (Eet_Message),
189 conn->user_data);
185 return EINA_TRUE; 190 return EINA_TRUE;
186} 191}
187 192
188EAPI Eina_Bool 193EAPI Eina_Bool
189eet_connection_send(Eet_Connection *conn, Eet_Data_Descriptor *edd, const void *data_in, const char *cipher_key) 194eet_connection_send(Eet_Connection *conn,
195 Eet_Data_Descriptor *edd,
196 const void *data_in,
197 const char *cipher_key)
190{ 198{
191 void *flat_data; 199 void *flat_data;
192 int data_size; 200 int data_size;
193 Eina_Bool ret = EINA_FALSE; 201 Eina_Bool ret = EINA_FALSE;
194 202
195 flat_data = eet_data_descriptor_encode_cipher(edd, data_in, cipher_key, &data_size); 203 flat_data = eet_data_descriptor_encode_cipher(edd,
204 data_in,
205 cipher_key,
206 &data_size);
196 if (!flat_data) 207 if (!flat_data)
197 return EINA_FALSE; 208 return EINA_FALSE;
198 209
199 if (_eet_connection_raw_send(conn, flat_data, data_size)) 210 if (_eet_connection_raw_send(conn, flat_data, data_size))
200 ret = EINA_TRUE; 211 ret = EINA_TRUE;
201 212
202 free(flat_data); 213 free(flat_data);
203 return ret; 214 return ret;
204} 215}
205 216
206EAPI Eina_Bool 217EAPI Eina_Bool
207eet_connection_node_send(Eet_Connection *conn, Eet_Node *node, const char *cipher_key) 218eet_connection_node_send(Eet_Connection *conn,
219 Eet_Node *node,
220 const char *cipher_key)
208{ 221{
209 void *data; 222 void *data;
210 int data_size; 223 int data_size;
@@ -212,10 +225,10 @@ eet_connection_node_send(Eet_Connection *conn, Eet_Node *node, const char *ciphe
212 225
213 data = eet_data_node_encode_cipher(node, cipher_key, &data_size); 226 data = eet_data_node_encode_cipher(node, cipher_key, &data_size);
214 if (!data) 227 if (!data)
215 return EINA_FALSE; 228 return EINA_FALSE;
216 229
217 if (_eet_connection_raw_send(conn, data, data_size)) 230 if (_eet_connection_raw_send(conn, data, data_size))
218 ret = EINA_TRUE; 231 ret = EINA_TRUE;
219 232
220 free(data); 233 free(data);
221 return ret; 234 return ret;
@@ -227,10 +240,10 @@ eet_connection_close(Eet_Connection *conn, Eina_Bool *on_going)
227 void *user_data; 240 void *user_data;
228 241
229 if (!conn) 242 if (!conn)
230 return NULL; 243 return NULL;
231 244
232 if (on_going) 245 if (on_going)
233 *on_going = conn->received == 0 ? EINA_FALSE : EINA_TRUE; 246 *on_going = conn->received == 0 ? EINA_FALSE : EINA_TRUE;
234 247
235 user_data = conn->user_data; 248 user_data = conn->user_data;
236 249