Changeset 99c2e9f3 in mainline for uspace/srv/hid/remcons/remcons.c
- Timestamp:
- 2012-01-12T09:29:00Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2a180307
- Parents:
- 261bbdc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/remcons/remcons.c
r261bbdc r99c2e9f3 74 74 sizeof(telnet_force_character_mode_command) / sizeof(telnet_cmd_t); 75 75 76 /** Creates new keyboard event from given char.77 *78 * @param type Event type (press / release).79 * @param c Pressed character.80 */81 static kbd_event_t* new_kbd_event(kbd_event_type_t type, wchar_t c) {82 kbd_event_t *event = malloc(sizeof(kbd_event_t));83 assert(event);84 85 link_initialize(&event->link);86 event->type = type;87 event->c = c;88 event->mods = 0;89 event->key = (c == '\n' ? KC_ENTER : KC_A);90 91 return event;92 }93 76 94 77 /** Handling client requests (VFS and console interface). … … 101 84 ipc_call_t call; 102 85 ipc_callid_t callid = 0; 86 87 /* 88 * The getterm task might terminate while we are here, 89 * waiting for a call. Also, the socket might be closed 90 * meanwhile. 91 * We want to detect this situation early, so we use a 92 * timeout variant of async_get_call(). 93 */ 103 94 while (callid == 0) { 104 95 callid = async_get_call_timeout(&call, 1000); 105 96 106 fibril_mutex_lock(&user->guard); 107 bool bail_out = user->socket_closed || user->task_finished; 108 fibril_mutex_unlock(&user->guard); 109 110 if (bail_out) { 97 if (telnet_user_is_zombie(user)) { 111 98 if (callid != 0) { 112 99 async_answer_0(callid, EINTR); … … 117 104 118 105 if (!IPC_GET_IMETHOD(call)) { 119 /* Clean-up. */120 106 return; 121 107 } … … 129 115 break; 130 116 case CONSOLE_GET_EVENT: { 131 if (list_empty(&user->in_events.list)) { 132 retry: 133 if (user->socket_buffer_len <= user->socket_buffer_pos) { 134 int recv_length = recv(user->socket, user->socket_buffer, BUFFER_SIZE, 0); 135 if ((recv_length == 0) || (recv_length == ENOTCONN)) { 136 fibril_mutex_lock(&user->guard); 137 user->socket_closed = true; 138 fibril_mutex_unlock(&user->guard); 139 async_answer_0(callid, ENOENT); 140 return; 141 } 142 if (recv_length < 0) { 143 async_answer_0(callid, EINVAL); 144 return; 145 } 146 user->socket_buffer_len = recv_length; 147 user->socket_buffer_pos = 0; 148 } 149 char data = user->socket_buffer[user->socket_buffer_pos++]; 150 if (data == 13) { 151 data = 10; 152 } 153 if (data == 0) 154 goto retry; 155 156 kbd_event_t *down = new_kbd_event(KEY_PRESS, data); 157 kbd_event_t *up = new_kbd_event(KEY_RELEASE, data); 158 assert(down); 159 assert(up); 160 prodcons_produce(&user->in_events, &down->link); 161 prodcons_produce(&user->in_events, &up->link); 162 } 163 164 165 link_t *link = prodcons_consume(&user->in_events); 166 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 167 async_answer_4(callid, EOK, event->type, event->key, event->mods, event->c); 168 free(event); 117 kbd_event_t event; 118 int rc = telnet_user_get_next_keyboard_event(user, &event); 119 if (rc != EOK) { 120 /* Silently ignore. */ 121 async_answer_0(callid, EOK); 122 break; 123 } 124 async_answer_4(callid, EOK, event.type, event.key, event.mods, event.c); 169 125 break; 170 126 } … … 185 141 break; 186 142 } 187 buf_converted = malloc(2 * size );143 buf_converted = malloc(2 * size + 1); 188 144 assert(buf_converted); 189 145 int buf_converted_size = 0; … … 197 153 } 198 154 } 155 /* Add terminating zero for printing purposes. */ 156 buf_converted[buf_converted_size] = 0; 157 158 fibril_mutex_lock(&user->guard); 199 159 rc = send(user->socket, buf_converted, buf_converted_size, 0); 160 fibril_mutex_unlock(&user->guard); 200 161 free(buf); 201 162 … … 206 167 207 168 async_answer_1(callid, EOK, size); 208 209 169 break; 210 170 } … … 249 209 return; 250 210 } 211 async_answer_0(iid, EOK); 251 212 252 213 telnet_user_log(user, "New client connected (%" PRIxn").", iid); 253 254 /* Accept the connection, increment reference. */255 async_answer_0(iid, EOK);256 214 257 215 /* Force character mode. */ … … 259 217 telnet_force_character_mode_command_count, 0); 260 218 219 /* Handle messages. */ 261 220 client_connection_message_loop(user); 262 221 263 /* Announce user disconnection. */264 222 telnet_user_notify_client_disconnected(user); 265 223 telnet_user_log(user, "Client disconnected (%" PRIxn").", iid);
Note:
See TracChangeset
for help on using the changeset viewer.