Lines Matching refs:ctx
33 static int process_command(context *ctx);
36 number(context *ctx)
40 while (isdigit(ctx->buffer[ctx->index])) {
42 result += ctx->buffer[ctx->index] - '0';
43 ctx->index++;
51 value(context *ctx)
53 if (ctx->buffer[ctx->index] == '[') {
54 ctx->index++;
55 int upper, lower = number(ctx);
56 if (ctx->buffer[ctx->index] == ',') {
57 ctx->index++;
58 upper = number(ctx);
67 return number(ctx);
72 repeat(context *ctx)
74 int max, saved, count = number(ctx);
76 max = saved = ctx->index;
78 ctx->index = saved;
79 if (process_command(ctx) < 0)
81 if (ctx->index > max)
82 max = ctx->index;
85 ctx->index = max;
91 send_packet(context *ctx, size_t bytes)
100 ptr[i] = ctx->generator + '0';
101 ctx->generator = (ctx->generator + 1) % 10;
104 send(ctx->sock, ptr, bytes, 0);
112 process_command(context *ctx)
114 while (ctx->buffer[ctx->index] != '.') {
115 ctx->index++;
117 switch (ctx->buffer[ctx->index - 1]) {
119 if (repeat(ctx) < 0)
124 send_packet(ctx, 1);
128 send_packet(ctx, value(ctx));
132 usleep(value(ctx) * 1000);
137 int value = number(ctx);
138 setsockopt(ctx->sock, SOL_SOCKET, SO_SNDBUF, &value,
153 read_command(context *ctx)
158 int size = recv(ctx->sock, ctx->buffer + index, 1, 0);
165 } while (ctx->buffer[index - 1] != '.');
167 ctx->index = 0;
168 return process_command(ctx);
175 context ctx = { *(int *)data, 0 };
177 while (read_command(&ctx) == 0);
179 fprintf(stderr, "Client %d leaving.\n", ctx.sock);
181 close(ctx.sock);