Changeset 1626 for branches/daemon
- Timestamp:
- Apr 1, 2007, 2:19:09 AM (15 years ago)
- Location:
- branches/daemon/daemon
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/daemon/daemon/client.c
r1617 r1626 49 49 struct con 50 50 { 51 int fd; 51 int infd; 52 int outfd; 52 53 struct ipc_info ipc; 53 struct bufferevent * ev; 54 struct bufferevent * evin; 55 struct bufferevent * evout; 54 56 }; 55 57 … … 83 85 static struct req * addreq ( enum ipc_msg, int64_t, struct resp ** ); 84 86 static int addintlistreq ( enum ipc_msg, size_t, const int * ); 87 static void noop ( struct bufferevent *, void * ); 88 static void noway ( struct bufferevent *, void * ); 85 89 static void didwrite ( struct bufferevent *, void * ); 86 90 static void ohshit ( struct bufferevent *, short, void * ); 87 91 static void canread ( struct bufferevent *, void * ); 88 92 static void flushreqs ( struct con * ); 89 static int sendvers ( struct bufferevent* );93 static int sendvers ( struct con * ); 90 94 static void infomsg ( enum ipc_msg, benc_val_t *, int64_t, void * ); 91 95 static void statmsg ( enum ipc_msg, benc_val_t *, int64_t, void * ); … … 128 132 129 133 int 130 client_ connect( const char * path )134 client_new_sock( const char * path ) 131 135 { 132 136 struct sockaddr_un sun; … … 162 166 } 163 167 ipc_newcon( &con->ipc, gl_tree ); 164 con-> fd= fd;165 con->ev 166 if( NULL == con->ev )168 con->infd = fd; 169 con->evin = bufferevent_new( fd, canread, didwrite, ohshit, con ); 170 if( NULL == con->evin ) 167 171 { 168 172 mallocmsg( -1 ); … … 171 175 return -1; 172 176 } 173 bufferevent_base_set( gl_base, con->ev ); 174 bufferevent_settimeout( con->ev, SERVER_TIMEOUT, SERVER_TIMEOUT ); 175 bufferevent_enable( con->ev, EV_READ ); 176 if( 0 > sendvers( con->ev ) ) 177 con->outfd = con->infd; 178 con->evout = con->evin; 179 bufferevent_base_set( gl_base, con->evin ); 180 bufferevent_settimeout( con->evin, SERVER_TIMEOUT, SERVER_TIMEOUT ); 181 bufferevent_enable( con->evin, EV_READ ); 182 if( 0 > sendvers( con ) ) 183 { 184 exit( 1 ); 185 } 186 187 return 0; 188 } 189 190 int 191 client_new_cmd( char * const * cmd ) 192 { 193 struct con * con; 194 int tocmd[2], fromcmd[2]; 195 pid_t kid; 196 197 assert( NULL != gl_base ); 198 assert( NULL != cmd && NULL != cmd[0] ); 199 200 if( 0 > pipe( tocmd ) ) 201 { 202 errnomsg( "failed to create pipe" ); 203 return -1; 204 } 205 206 if( 0 > pipe( fromcmd ) ) 207 { 208 errnomsg( "failed to create pipe" ); 209 close( tocmd[0] ); 210 close( tocmd[1] ); 211 return -1; 212 } 213 214 kid = fork(); 215 if( 0 > kid ) 216 { 217 close( tocmd[0] ); 218 close( tocmd[1] ); 219 close( fromcmd[0] ); 220 close( fromcmd[1] ); 221 return -1; 222 } 223 else if( 0 == kid ) 224 { 225 if( 0 > dup2( tocmd[0], STDIN_FILENO ) || 226 0 > dup2( fromcmd[1], STDOUT_FILENO ) ) 227 { 228 errnomsg( "failed to duplicate descriptors" ); 229 _exit( 1 ); 230 } 231 close( tocmd[0] ); 232 close( tocmd[1] ); 233 close( fromcmd[0] ); 234 close( fromcmd[1] ); 235 execvp( cmd[0], cmd ); 236 errnomsg( "failed to execute: %s", cmd[0] ); 237 _exit( 1 ); 238 } 239 240 close( tocmd[0] ); 241 close( fromcmd[1] ); 242 243 con = calloc( 1, sizeof *con ); 244 if( NULL == con ) 245 { 246 mallocmsg( sizeof *con ); 247 close( tocmd[1] ); 248 close( fromcmd[0] ); 249 return -1; 250 } 251 252 con->infd = fromcmd[0]; 253 con->evin = bufferevent_new( con->infd, canread, noop, ohshit, con ); 254 if( NULL == con->evin ) 255 { 256 free( con ); 257 close( tocmd[1] ); 258 close( fromcmd[0] ); 259 return -1; 260 } 261 bufferevent_base_set( gl_base, con->evin ); 262 bufferevent_settimeout( con->evin, SERVER_TIMEOUT, SERVER_TIMEOUT ); 263 bufferevent_enable( con->evin, EV_READ ); 264 265 con->outfd = tocmd[1]; 266 con->evout = bufferevent_new( con->outfd, noway, didwrite, ohshit, con ); 267 if( NULL == con->evout ) 268 { 269 bufferevent_free( con->evin ); 270 free( con ); 271 close( tocmd[1] ); 272 close( fromcmd[0] ); 273 return -1; 274 } 275 bufferevent_base_set( gl_base, con->evout ); 276 bufferevent_settimeout( con->evout, SERVER_TIMEOUT, SERVER_TIMEOUT ); 277 bufferevent_enable( con->evout, EV_READ ); 278 279 ipc_newcon( &con->ipc, gl_tree ); 280 if( 0 > sendvers( con ) ) 177 281 { 178 282 exit( 1 ); … … 469 573 470 574 void 471 didwrite( struct bufferevent * ev, void * arg ) 575 noop( struct bufferevent * ev UNUSED, void * arg UNUSED ) 576 { 577 /* libevent prior to 1.2 couldn't handle a NULL write callback */ 578 } 579 580 void 581 noway( struct bufferevent * evin, void * arg UNUSED ) 582 { 583 /* this shouldn't happen, but let's drain the buffer anyway */ 584 evbuffer_drain( EVBUFFER_INPUT( evin ), 585 EVBUFFER_LENGTH( EVBUFFER_INPUT( evin ) ) ); 586 } 587 588 void 589 didwrite( struct bufferevent * evout, void * arg ) 472 590 { 473 591 struct con * con = arg; 474 592 475 assert( ev == con->ev);593 assert( evout == con->evout ); 476 594 flushreqs( con ); 477 595 } … … 508 626 509 627 void 510 canread( struct bufferevent * ev , void * arg )628 canread( struct bufferevent * evin, void * arg ) 511 629 { 512 630 struct con * con = arg; … … 515 633 ssize_t res; 516 634 517 buf = EVBUFFER_DATA( EVBUFFER_INPUT( ev ) ); 518 len = EVBUFFER_LENGTH( EVBUFFER_INPUT( ev ) ); 635 assert( evin == con->evin ); 636 buf = EVBUFFER_DATA( EVBUFFER_INPUT( evin ) ); 637 len = EVBUFFER_LENGTH( EVBUFFER_INPUT( evin ) ); 519 638 520 639 if( IPC_MIN_MSG_LEN > len ) … … 543 662 if( 0 < res ) 544 663 { 545 evbuffer_drain( EVBUFFER_INPUT( ev ), res );664 evbuffer_drain( EVBUFFER_INPUT( evin ), res ); 546 665 flushreqs( con ); 547 666 } … … 622 741 exit( 1 ); 623 742 } 624 if( 0 > bufferevent_write( con->ev , buf, buflen ) )743 if( 0 > bufferevent_write( con->evout, buf, buflen ) ) 625 744 { 626 745 errmsg( "failed to buffer %zd bytes of data for write", buflen ); … … 632 751 633 752 int 634 sendvers( struct bufferevent * ev)753 sendvers( struct con * con ) 635 754 { 636 755 uint8_t * buf; … … 651 770 } 652 771 653 if( 0 > bufferevent_write( ev, buf, len ) )772 if( 0 > bufferevent_write( con->evout, buf, len ) ) 654 773 { 655 774 free( buf ); -
branches/daemon/daemon/client.h
r1617 r1626 36 36 37 37 int client_init ( struct event_base * ); 38 int client_connect ( const char * ); 38 int client_new_sock ( const char * ); 39 int client_new_cmd ( char * const * ); 39 40 int client_quit ( void ); 40 41 int client_addfiles ( struct strlist * ); -
branches/daemon/daemon/remote.c
r1623 r1626 46 46 struct opts 47 47 { 48 int proxy; 49 char ** proxycmd; 48 50 enum confpathtype type; 49 51 struct strlist files; … … 139 141 140 142 evbase = event_init(); 141 142 confpath( sockpath, sizeof sockpath, CONF_FILE_SOCKET, o.type );143 143 client_init( evbase ); 144 client_connect( sockpath ); 144 145 if( o.proxy ) 146 { 147 client_new_cmd( o.proxycmd ); 148 } 149 else 150 { 151 confpath( sockpath, sizeof sockpath, CONF_FILE_SOCKET, o.type ); 152 client_new_sock( sockpath ); 153 } 145 154 146 155 if( ( o.sendquit && 0 > client_quit ( ) ) || … … 194 203 195 204 printf( 196 "usage: %s [options] [files]...\n"205 "usage: %s [options]\n" 197 206 "\n" 198 207 "Transmission %s (r%d) http://transmission.m0k.org/\n" … … 219 228 " -t --type gtk Use the GTK+ frontend, transmission-gtk\n" 220 229 " -u --upload-limit <int> Max upload rate in KiB/s\n" 221 " -U --upload-unlimited No upload rate limit\n", 230 " -U --upload-unlimited No upload rate limit\n" 231 " -x --proxy Use proxy command to connect to frontend\n", 222 232 getmyname(), VERSION_STRING, VERSION_REVISION ); 223 233 exit( 0 ); … … 227 237 readargs( int argc, char ** argv, struct opts * opts ) 228 238 { 229 char optstr[] = "a:d:Df:hilmMp:qr:s:S:t:u:U ";239 char optstr[] = "a:d:Df:hilmMp:qr:s:S:t:u:Ux"; 230 240 struct option longopts[] = 231 241 { … … 247 257 { "upload-limit", required_argument, NULL, 'u' }, 248 258 { "upload-unlimited", no_argument, NULL, 'U' }, 259 { "proxy", no_argument, NULL, 'U' }, 249 260 { NULL, 0, NULL, 0 } 250 261 }; … … 343 354 opts->up = -1; 344 355 break; 356 case 'x': 357 opts->proxy = 1; 358 break; 345 359 default: 346 360 usage( NULL ); … … 355 369 } 356 370 357 if( 0 > fileargs( &opts->files, argc - optind, argv + optind ) ) 371 if( opts->proxy ) 372 { 373 opts->proxycmd = argv + optind; 374 } 375 else if( 0 > fileargs( &opts->files, argc - optind, argv + optind ) ) 358 376 { 359 377 return -1;
Note: See TracChangeset
for help on using the changeset viewer.