comparison src/c/urweb.c @ 1447:17393c5e2b90

Send newly created sources with messages to clients
author Adam Chlipala <adam@chlipala.net>
date Sat, 09 Apr 2011 20:00:52 -0400
parents 36f7d1debb37
children 37599e85bba8
comparison
equal deleted inserted replaced
1446:36f7d1debb37 1447:17393c5e2b90
309 static uw_Basis_channel new_channel(client *c) { 309 static uw_Basis_channel new_channel(client *c) {
310 uw_Basis_channel ch = {c->id, c->n_channels++}; 310 uw_Basis_channel ch = {c->id, c->n_channels++};
311 return ch; 311 return ch;
312 } 312 }
313 313
314 static void client_send(client *c, uw_buffer *msg) { 314 static void client_send(client *c, uw_buffer *msg, const char *script, int script_len) {
315 pthread_mutex_lock(&c->lock); 315 pthread_mutex_lock(&c->lock);
316 316
317 if (c->sock != -1) { 317 if (c->sock != -1) {
318 c->send(c->sock, on_success, strlen(on_success)); 318 c->send(c->sock, on_success, strlen(on_success));
319 c->send(c->sock, begin_msgs, sizeof(begin_msgs) - 1); 319 c->send(c->sock, begin_msgs, sizeof(begin_msgs) - 1);
320 if (script_len > 0) {
321 c->send(c->sock, "E\n", 2);
322 c->send(c->sock, script, script_len);
323 c->send(c->sock, "\n", 1);
324 }
320 c->send(c->sock, msg->start, uw_buffer_used(msg)); 325 c->send(c->sock, msg->start, uw_buffer_used(msg));
321 c->close(c->sock); 326 c->close(c->sock);
322 c->sock = -1; 327 c->sock = -1;
323 } else if (uw_buffer_append(&c->msgs, msg->start, uw_buffer_used(msg))) 328 } else if ((script_len > 0
329 && (c->send(c->sock, "E\n", 2)
330 || c->send(c->sock, script, script_len)
331 || c->send(c->sock, "\n", 1)))
332 || uw_buffer_append(&c->msgs, msg->start, uw_buffer_used(msg)))
324 fprintf(stderr, "Client message buffer size exceeded"); 333 fprintf(stderr, "Client message buffer size exceeded");
325 334
326 pthread_mutex_unlock(&c->lock); 335 pthread_mutex_unlock(&c->lock);
327 } 336 }
328 337
3165 delta *d = &ctx->deltas[i]; 3174 delta *d = &ctx->deltas[i];
3166 client *c = find_client(d->client); 3175 client *c = find_client(d->client);
3167 3176
3168 assert (c != NULL && c->mode == USED); 3177 assert (c != NULL && c->mode == USED);
3169 3178
3170 client_send(c, &d->msgs); 3179 client_send(c, &d->msgs, ctx->script.start, uw_buffer_used(&ctx->script));
3171 } 3180 }
3172 3181
3173 if (ctx->client) 3182 if (ctx->client)
3174 release_client(ctx->client); 3183 release_client(ctx->client);
3175 3184