Lines Matching refs:client
52 Client client = calloc( sizeof(*client), 1 ); in client_alloc() local
54 client->channel = channel; in client_alloc()
55 return client; in client_alloc()
59 client_free( Client client ) in client_free() argument
61 sys_channel_close( client->channel ); in client_free()
62 client->channel = NULL; in client_free()
63 free( client ); in client_free()
67 client_append( Client client, const char* str, int len );
70 client_handle_line( Client client, const char* cmd ) in client_handle_line() argument
93 printf( "%p: << %s\n", client, temp ); in client_handle_line()
96 printf( "client %p quitting\n", client ); in client_handle_line()
97 client_free( client ); in client_handle_line()
100 client_append( client, "type 'quit' to quit\n", -1 ); in client_handle_line()
106 Client client = _client; in client_handler() local
111 ret = sys_channel_read( client->channel, client->in_buff + client->in_pos, 1 ); in client_handler()
114 client, ret, strerror(errno) ); in client_handler()
117 if (client->in_buff[client->in_pos] == '\r' || in client_handler()
118 client->in_buff[client->in_pos] == '\n' ) { in client_handler()
119 const char* cmd = client->in_buff; in client_handler()
120 client->in_buff[client->in_pos] = 0; in client_handler()
126 client_handle_line( client, cmd ); in client_handler()
127 client->in_pos = 0; in client_handler()
129 client->in_pos += 1; in client_handler()
135 ret = sys_channel_write( client->channel, client->out_buff + client->out_pos, 1 ); in client_handler()
138 client, ret, strerror(errno) ); in client_handler()
141 client->out_pos += 1; in client_handler()
142 if (client->out_pos == client->out_size) { in client_handler()
143 client->out_size = 0; in client_handler()
144 client->out_pos = 0; in client_handler()
146 sys_channel_on( client->channel, SYS_EVENT_READ, client_handler, client ); in client_handler()
152 printf( "client %p exiting\n", client ); in client_handler()
153 client_free( client ); in client_handler()
157 client_append( Client client, const char* str, int len ) in client_append() argument
164 avail = sizeof(client->out_buff) - client->out_size; in client_append()
168 memcpy( client->out_buff + client->out_size, str, len ); in client_append()
169 if (client->out_size == 0) { in client_append()
170 sys_channel_on( client->channel, SYS_EVENT_READ | SYS_EVENT_WRITE, client_handler, client ); in client_append()
172 client->out_size += len; in client_append()
181 Client client; in accept_func() local
186 client = client_alloc( handler ); in accept_func()
189 sys_channel_on( handler, SYS_EVENT_READ, client_handler, client ); in accept_func()
190 client_append( client, "Welcome !\n", -1 ); in accept_func()