summaryrefslogtreecommitdiff
path: root/legacy/eet/src/lib
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2011-12-29 12:59:55 +0000
committerCarsten Haitzler <raster@rasterman.com>2011-12-29 12:59:55 +0000
commit78e67d72d7ba417d48f258a251ee574ad579f4f8 (patch)
tree1b99f9cad2a2aa00de272c2029ff5d1ec5897e78 /legacy/eet/src/lib
parente735350d91cc97e1f8ec7d6164d2bacc9e56c981 (diff)
formatting niceness.
SVN revision: 66631
Diffstat (limited to 'legacy/eet/src/lib')
-rw-r--r--legacy/eet/src/lib/eet_connection.c61
1 files changed, 27 insertions, 34 deletions
diff --git a/legacy/eet/src/lib/eet_connection.c b/legacy/eet/src/lib/eet_connection.c
index 6036a5a2e3..a11816ffa8 100644
--- a/legacy/eet/src/lib/eet_connection.c
+++ b/legacy/eet/src/lib/eet_connection.c
@@ -56,18 +56,18 @@ eet_connection_new(Eet_Read_Cb *eet_read_cb,
56 const void *user_data) 56 const void *user_data)
57{ 57{
58 Eet_Connection *conn; 58 Eet_Connection *conn;
59 59
60 if (!eet_read_cb || !eet_write_cb) 60 if (!eet_read_cb || !eet_write_cb)
61 return NULL; 61 return NULL;
62 62
63 conn = calloc(1, sizeof (Eet_Connection)); 63 conn = calloc(1, sizeof (Eet_Connection));
64 if (!conn) 64 if (!conn)
65 return NULL; 65 return NULL;
66 66
67 conn->eet_read_cb = eet_read_cb; 67 conn->eet_read_cb = eet_read_cb;
68 conn->eet_write_cb = eet_write_cb; 68 conn->eet_write_cb = eet_write_cb;
69 conn->user_data = (void *)user_data; 69 conn->user_data = (void *)user_data;
70 70
71 return conn; 71 return conn;
72} 72}
73 73
@@ -76,54 +76,46 @@ eet_connection_received(Eet_Connection *conn,
76 const void *data, 76 const void *data,
77 size_t size) 77 size_t size)
78{ 78{
79 if ((!conn) || (!data) || (!size)) 79 if ((!conn) || (!data) || (!size)) return size;
80 return size; 80 do
81 81 {
82 do {
83 size_t copy_size; 82 size_t copy_size;
84 83
85 if (conn->size == 0) 84 if (conn->size == 0)
86 { 85 {
87 const int *msg; 86 const int *msg;
88 size_t packet_size; 87 size_t packet_size;
89 88
90 if (size < sizeof (int) * 2) 89 if (size < sizeof (int) * 2) break;
91 break;
92 90
93 msg = data; 91 msg = data;
94 /* Check the magic */ 92 /* Check the magic */
95 if (ntohl(msg[0]) != MAGIC_EET_DATA_PACKET) 93 if (ntohl(msg[0]) != MAGIC_EET_DATA_PACKET) break;
96 break;
97 94
98 packet_size = ntohl(msg[1]); 95 packet_size = ntohl(msg[1]);
99 /* Message should always be under 64K */ 96 /* Message should always be under 64K */
100 if (packet_size > 64 * 1024) 97 if (packet_size > 64 * 1024) break;
101 break;
102 98
103 data = (void *)(msg + 2); 99 data = (void *)(msg + 2);
104 size -= sizeof (int) * 2; 100 size -= sizeof (int) * 2;
105 if ((size_t)packet_size <= size) 101 if ((size_t)packet_size <= size)
106 { 102 {
107 /* Not a partial receive, go the quick way. */ 103 /* Not a partial receive, go the quick way. */
108 if (!conn->eet_read_cb(data, packet_size, conn->user_data)) 104 if (!conn->eet_read_cb(data, packet_size, conn->user_data))
109 break; 105 break;
110 106
111 data = (void *)((char *)data + packet_size); 107 data = (void *)((char *)data + packet_size);
112 size -= packet_size; 108 size -= packet_size;
113
114 conn->received = 0; 109 conn->received = 0;
115 continue; 110 continue;
116 } 111 }
117
118 conn->size = packet_size; 112 conn->size = packet_size;
119 if (conn->allocated < conn->size) 113 if (conn->allocated < conn->size)
120 { 114 {
121 void *tmp; 115 void *tmp;
122 116
123 tmp = realloc(conn->buffer, conn->size); 117 tmp = realloc(conn->buffer, conn->size);
124 if (!tmp) 118 if (!tmp) break;
125 break;
126
127 conn->buffer = tmp; 119 conn->buffer = tmp;
128 conn->allocated = conn->size; 120 conn->allocated = conn->size;
129 } 121 }
@@ -132,31 +124,32 @@ eet_connection_received(Eet_Connection *conn,
132 /* Partial receive */ 124 /* Partial receive */
133 copy_size = 125 copy_size =
134 (conn->size - conn->received >= 126 (conn->size - conn->received >=
135 size) ? size : conn->size - conn->received; 127 size) ? size : conn->size - conn->received;
136 memcpy((char *)conn->buffer + conn->received, data, copy_size); 128 memcpy((char *)conn->buffer + conn->received, data, copy_size);
137 129
138 conn->received += copy_size; 130 conn->received += copy_size;
139 data = (void *)((char *)data + copy_size); 131 data = (void *)((char *)data + copy_size);
140 size -= copy_size; 132 size -= copy_size;
141 133
142 if (conn->received == conn->size) 134 if (conn->received == conn->size)
143 { 135 {
144 size_t data_size; 136 size_t data_size;
145 137
146 data_size = conn->size; 138 data_size = conn->size;
147 conn->size = 0; 139 conn->size = 0;
148 conn->received = 0; 140 conn->received = 0;
149 141
150 /* Completed a packet. */ 142 /* Completed a packet. */
151 if (!conn->eet_read_cb(conn->buffer, data_size, conn->user_data)) 143 if (!conn->eet_read_cb(conn->buffer, data_size, conn->user_data))
152 { 144 {
153 /* Something goes wrong. Stop now. */ 145 /* Something goes wrong. Stop now. */
154 size += data_size; 146 size += data_size;
155 break; 147 break;
156 } 148 }
157 } 149 }
158 } while (size > 0); 150 }
159 151 while (size > 0);
152
160 return size; 153 return size;
161} 154}
162 155