24
24
#include <ggl/object.h>
25
25
#include <ggl/socket.h>
26
26
#include <ggl/vector.h>
27
+ #include <inttypes.h>
27
28
#include <limits.h>
28
29
#include <pthread.h>
29
30
#include <string.h>
@@ -64,9 +65,7 @@ static GglError get_message(
64
65
int conn ,
65
66
GglBuffer recv_buffer ,
66
67
EventStreamMessage * msg ,
67
- EventStreamCommonHeaders * common_headers ,
68
- GglAlloc * alloc ,
69
- GglObject * payload
68
+ EventStreamCommonHeaders * common_headers
70
69
) {
71
70
assert (msg != NULL );
72
71
@@ -109,14 +108,6 @@ static GglError get_message(
109
108
}
110
109
}
111
110
112
- if (payload != NULL ) {
113
- ret = ggl_json_decode_destructive (msg -> payload , alloc , payload );
114
- if (ret != GGL_ERR_OK ) {
115
- return ret ;
116
- }
117
- msg -> payload .len = 0 ;
118
- }
119
-
120
111
return GGL_ERR_OK ;
121
112
}
122
113
@@ -150,7 +141,8 @@ GglError ggipc_connect_auth(GglBuffer socket_path, GglBuffer *svcuid, int *fd) {
150
141
EventStreamMessage msg = { 0 };
151
142
EventStreamCommonHeaders common_headers ;
152
143
153
- ret = get_message (conn , recv_buffer , & msg , & common_headers , NULL , NULL );
144
+ ret = get_message (conn , recv_buffer , & msg , & common_headers );
145
+
154
146
if (ret != GGL_ERR_OK ) {
155
147
return ret ;
156
148
}
@@ -165,6 +157,10 @@ GglError ggipc_connect_auth(GglBuffer socket_path, GglBuffer *svcuid, int *fd) {
165
157
return GGL_ERR_FAILURE ;
166
158
}
167
159
160
+ if (msg .payload .len != 0 ) {
161
+ GGL_LOGW ("Eventstream connection ack has unexpected payload." );
162
+ }
163
+
168
164
EventStreamHeaderIter iter = msg .headers ;
169
165
EventStreamHeader header ;
170
166
@@ -222,6 +218,7 @@ GglError ggipc_call(
222
218
223
219
GglError ret = send_message (conn , headers , headers_len , & params );
224
220
if (ret != GGL_ERR_OK ) {
221
+ GGL_LOGE ("Failed to send message %d" , ret );
225
222
return ret ;
226
223
}
227
224
@@ -231,28 +228,50 @@ GglError ggipc_call(
231
228
EventStreamMessage msg = { 0 };
232
229
EventStreamCommonHeaders common_headers ;
233
230
234
- ret = get_message (conn , recv_buffer , & msg , & common_headers , alloc , result );
231
+ ret = get_message (conn , recv_buffer , & msg , & common_headers );
235
232
if (ret != GGL_ERR_OK ) {
233
+ GGL_LOGE ("get_message returned %d" , ret );
236
234
return ret ;
237
235
}
238
236
239
- if (result != NULL ) {
240
- ret = ggl_obj_buffer_copy (result , alloc );
241
- if (ret != GGL_ERR_OK ) {
242
- return ret ;
243
- }
244
- }
245
-
246
237
if (common_headers .stream_id != 1 ) {
247
238
GGL_LOGE ("Unknown stream id received." );
248
239
return GGL_ERR_FAILURE ;
249
240
}
250
241
242
+ if (common_headers .message_type == EVENTSTREAM_APPLICATION_ERROR ) {
243
+ GGL_LOGI (
244
+ "Received IPC error on stream %" PRId32 ". Payload: %.*s." ,
245
+ common_headers .stream_id ,
246
+ (int ) msg .payload .len ,
247
+ msg .payload .data
248
+ );
249
+ return GGL_ERR_FAILURE ;
250
+ }
251
+
251
252
if (common_headers .message_type != EVENTSTREAM_APPLICATION_MESSAGE ) {
252
- GGL_LOGE ("Connection response not an ack." );
253
+ GGL_LOGE (
254
+ "Stream %" PRId32 " received invalid message type: %" PRId32 "." ,
255
+ common_headers .stream_id ,
256
+ common_headers .message_type
257
+ );
253
258
return GGL_ERR_FAILURE ;
254
259
}
255
260
261
+ if (result != NULL ) {
262
+ ret = ggl_json_decode_destructive (msg .payload , alloc , result );
263
+ if (ret != GGL_ERR_OK ) {
264
+ GGL_LOGE ("ggl_json_decode_destructive returned %d" , ret );
265
+ return ret ;
266
+ }
267
+
268
+ ret = ggl_obj_buffer_copy (result , alloc );
269
+ if (ret != GGL_ERR_OK ) {
270
+ GGL_LOGE ("Failed to copy buffer %d" , ret );
271
+ return ret ;
272
+ }
273
+ }
274
+
256
275
return GGL_ERR_OK ;
257
276
}
258
277
0 commit comments