Changeset 4948:29b5b41a1ca2 in roaraudio
- Timestamp:
- 05/10/11 01:41:14 (13 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
include/libroar/client.h
r4708 r4948 63 63 int roar_client_pass (struct roar_connection * con, struct roar_client * client, uint16_t flags); 64 64 65 int roar_client_exec (struct roar_connection * con, struct roar_client * client, uint16_t flags); 66 65 67 #endif 66 68 -
libroar/client.c
r4708 r4948 128 128 } 129 129 130 int roar_client_exec (struct roar_connection * con, struct roar_client * client, uint16_t flags) { 131 struct roar_message m; 132 int16_t * d = (int16_t *)m.data; 133 int i; 134 135 memset(&m, 0, sizeof(m)); 136 137 m.cmd = ROAR_CMD_EXEC_STREAM; 138 m.stream = -1; // client (non-stream) passs 139 m.pos = 0; 140 m.datalen = 4*2; 141 142 d[0] = 0; // version 143 d[1] = flags; 144 d[2] = client->proto; 145 d[3] = client->byteorder; 146 147 for (i = 0; i < 4; i++) 148 d[i] = ROAR_HOST2NET16(d[i]); 149 150 if ( roar_req(con, &m, NULL) == -1 ) 151 return -1; 152 153 client->fh = roar_get_connection_fh(con); 154 155 return 0; 156 } 157 130 158 //ll -
roarclients/roarclientpass.c
r4922 r4948 58 58 #define F_STDERR _BV(ROAR_STDERR) 59 59 60 int run (int client, int in, int out) { 61 struct roar_vio_calls socks[3]; 62 struct roar_vio_select vios[3]; 63 int alive = 1; 64 int ret; 65 ssize_t len; 66 char buf[1024]; 67 68 roar_vio_open_fh_socket(&(socks[0]), client); 69 roar_vio_open_fh_socket(&(socks[1]), in); 70 roar_vio_open_fh_socket(&(socks[2]), out); 71 72 ROAR_VIO_SELECT_SETVIO(&(vios[0]), &(socks[0]), ROAR_VIO_SELECT_READ|ROAR_VIO_SELECT_WRITE); 73 ROAR_VIO_SELECT_SETVIO(&(vios[1]), &(socks[1]), ROAR_VIO_SELECT_READ); 74 ROAR_VIO_SELECT_SETVIO(&(vios[2]), &(socks[2]), ROAR_VIO_SELECT_WRITE); 75 76 while (alive) { 77 ret = roar_vio_select(vios, 3, NULL, NULL); 78 if ( ret < 0 ) 79 break; 80 81 if ( ret == 0 ) 82 continue; 83 84 if ( (vios[0].eventsa & ROAR_VIO_SELECT_READ) && (vios[2].eventsa & ROAR_VIO_SELECT_WRITE) ) { 85 len = roar_vio_read(&(socks[0]), buf, sizeof(buf)); 86 87 if ( len < 1 ) { 88 alive = 0; 89 } else { 90 if ( roar_vio_write(&(socks[2]), buf, len) != len ) 91 break; 92 } 93 } 94 95 if ( (vios[0].eventsa & ROAR_VIO_SELECT_WRITE) && (vios[1].eventsa & ROAR_VIO_SELECT_READ) ) { 96 len = roar_vio_read(&(socks[1]), buf, sizeof(buf)); 97 98 if ( len < 1 ) { 99 alive = 0; 100 } else { 101 if ( roar_vio_write(&(socks[0]), buf, len) != len ) 102 break; 103 } 104 } 105 } 106 107 roar_vio_close(&(socks[0])); 108 roar_vio_close(&(socks[1])); 109 roar_vio_close(&(socks[2])); 110 111 return 0; 112 } 113 60 114 int main (int argc, char * argv[]) { 61 115 struct roar_connection con; … … 73 127 char * host = NULL; 74 128 int port = -1; 129 enum {PASSFH, EXEC} command = PASSFH; 75 130 76 131 for (i = 1; i < argc; i++) { … … 95 150 } else if ( !strcmp(k, "--listen") ) { 96 151 flags |= ROAR_CLIENTPASS_FLAG_LISTEN; 152 } else if ( !strcmp(k, "--command") ) { 153 k = argv[++i]; 154 if ( !strcasecmp(k, "passfh") ) { 155 command = PASSFH; 156 } else if ( !strcasecmp(k, "exec") ) { 157 command = EXEC; 158 } else { 159 ROAR_ERR("unknown command: %s", k); 160 return 1; 161 } 97 162 } else if ( !strcmp(k, "--mode") ) { 98 163 k = argv[++i]; … … 161 226 162 227 roar_client_new(&client); 163 roar_client_set_fh(&client, clientfh);164 228 roar_client_set_proto(&client, proto, byteorder); 229 230 if ( command != EXEC ) 231 roar_client_set_fh(&client, clientfh); 165 232 166 233 if ( roar_simple_connect(&con, server, "roarclientpass") == -1 ) { … … 169 236 } 170 237 171 if ( roar_client_pass(&con, &client, flags) == -1 ) { 172 ROAR_ERR("Can not pass client fh to server"); 173 roar_disconnect(&con); 174 return 20; 238 switch (command) { 239 case PASSFH: 240 if ( roar_client_pass(&con, &client, flags) == -1 ) { 241 ROAR_ERR("Can not pass client fh to server"); 242 roar_disconnect(&con); 243 return 20; 244 } 245 break; 246 case EXEC: 247 if ( roar_client_exec(&con, &client, flags) == -1 ) { 248 ROAR_ERR("Can not exec client on server"); 249 roar_disconnect(&con); 250 return 20; 251 } 252 253 if ( run(client.fh, clientfh, cflags & F_STDOUT ? ROAR_STDOUT : clientfh) == -1 ) { 254 ROAR_ERR("Can not run data copy runner"); 255 return 20; 256 } 257 258 return 0; 259 break; 175 260 } 176 261 -
roard/req.c
r4923 r4948 343 343 344 344 int req_on_exec_stream (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) { 345 struct roar_message m; 346 struct roar_client * c; 347 struct roar_connection con; 348 int16_t * d = (int16_t*)mes->data; 349 int sock; 350 int i; 345 351 int r; 346 352 … … 348 354 349 355 350 if ( streams_is_ready(mes->stream) ) { 351 flags[1] |= COMMAND_FLAG_OUT_CLOSECON; 352 } else { 353 if ( (r = client_stream_exec(client, mes->stream)) == -1 ) 354 return -1; 355 } 356 357 ROAR_DBG("req_on_exec_stream(client=%i, mes={stream=%i,...},...): returning (OK)...", client, mes->stream); 358 mes->cmd = ROAR_CMD_OK; 359 mes->datalen = 0; 356 if ( mes->stream != -1 ) { 357 if ( streams_is_ready(mes->stream) ) { 358 flags[1] |= COMMAND_FLAG_OUT_CLOSECON; 359 } else { 360 if ( (r = client_stream_exec(client, mes->stream)) == -1 ) 361 return -1; 362 } 363 364 ROAR_DBG("req_on_exec_stream(client=%i, mes={stream=%i,...},...): returning (OK)...", client, mes->stream); 365 mes->cmd = ROAR_CMD_OK; 366 mes->datalen = 0; 367 return 0; 368 } 369 370 if ( mes->datalen < 4*2 ) 371 return -1; 372 373 for (i = 0; i < 4; i++) { 374 d[i] = ROAR_NET2HOST16(d[i]); 375 } 376 377 if ( d[0] != 0 ) // version 378 return -1; 379 380 if ( d[1] != 0 ) // flags 381 return -1; 382 383 memset(&m, 0, sizeof(m)); 384 385 m.cmd = ROAR_CMD_OK; 386 387 flags[1] |= COMMAND_FLAG_OUT_NOSEND; 388 389 c = ROAR_CLIENT(g_clients[client]); 390 391 sock = c->fh; 392 393 if ( sock == -1 ) 394 return -1; 395 396 roar_connect_fh(&con, sock); 397 398 roar_send_message(&con, &m, NULL); 399 400 clients_set_fh(client, -1); 401 clients_delete(client); 402 403 clients_new_from_fh(sock, d[2], d[3], 1); 360 404 361 405 return 0;
Note: See TracChangeset
for help on using the changeset viewer.