Changeset 4948:29b5b41a1ca2 in roaraudio for roarclients/roarclientpass.c
- Timestamp:
- 05/10/11 01:41:14 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.