17
mbd_kbd.c
- #include "mbd_kbd.h"
- #include "mbd.h"
- #include <stdlib.h>
- #include <string.h>
- void kbd_open( int argc, char **argv ) {
- switch ( argc ) {
- case 1:
- mb_open( );
- break;
- case 2: {
- if ( strcmp( argv[ 1 ], "unix" ) == 0 )
- mb_open_unix( );
- else if ( strcmp( argv[ 1 ], "inet" ) == 0 )
- mb_open_inet( );
- else
- goto error;
- break;
- }
- default:
- error:
- fprintf( stderr, "open [unix | inet]\n" );
- break;
- }
- }
- void kbd_close( int argc, char **argv ) {
- switch ( argc ) {
- case 1:
- mb_close( );
- break;
- case 2: {
- char *p = argv[ 1 ];
- if ( *p == 'u' || *p == 'U' )
- mb_close_unix( );
- else if ( *p == 'i' || *p == 'I' )
- mb_close_inet( );
- else
- goto error;
- break;
- }
- default:
- error:
- fprintf( stderr, "%s [unix | inet]\n", argv[ 0 ] );
- break;
- }
- }
- void kbd_pagesize( int argc, char **argv ) {
- switch ( argc ) {
- case 2: {
- int size = atoi( argv[ 1 ] );
- if ( size > 0 )
- mb_setpagesize( size );
- else
- goto error;
- break;
- }
- case 1:
- fprintf( stdout, "%u\n", mb_getpagesize() );
- break;
- default:
- error:
- fprintf( stderr, "%s [nbytes]\n", argv[ 0 ] );
- break;
- }
- }
- void kbd_info( int argc, char **argv ) {
- struct mb_socket *s_in;
- int i, len;
- switch ( argc ) {
- case 1:
- len = list_length( mb.in_sockets );
- fprintf( stdout, "conn=%i total=%u msgs=%u\n", len, mb.n_conn, mb.n_msgs );
- for ( i = 0; i < len; i++ ) {
- s_in = (struct mb_socket *)list_get( mb.in_sockets, i );
- fprintf( stdout, "%s sent=%u recv=%u\n",
- s_in->s_name ? s_in->s_name : "anonymous",
- s_in->n_sent, s_in->n_recv
- );
- }
- break;
- default:
- fprintf( stderr, "%s\n", argv[ 0 ] );
- break;
- }
- }
- void kbd_timeout( int argc, char **argv ) {
- switch ( argc ) {
- case 2: {
- int size = atoi( argv[ 1 ] );
- if ( size > 0 )
- mb_settimeout( size );
- else
- goto error;
- break;
- }
- case 1:
- fprintf( stdout, "%u\n", mb_gettimeout() );
- break;
- default:
- error:
- fprintf( stderr, "%s [nsecs]\n", argv[ 0 ] );
- break;
- }
- }
- #if defined( DEBUG )
- #include "ctk/debug.h"
- void kbd_debug( int argc, char **argv ) {
- switch ( argc ) {
- case 2:
- debug = atoi( argv[ 1 ] );
- break;
- case 1:
- fprintf( stdout, "%i\n", debug );
- break;
- default:
- fprintf( stderr, "%s [level]\n", argv[ 0 ] );
- break;
- }
- }
- void kbd_dumpsize( int argc, char **argv ) {
- switch ( argc ) {
- case 2: {
- int size = atoi( argv[ 1 ] );
- if ( size > 0 )
- mb.dump_size = size;
- else
- goto error;
- break;
- }
- case 1:
- fprintf( stdout, "%u\n", mb.dump_size );
- break;
- default:
- error:
- fprintf( stderr, "%s [n_octets]\n", argv[ 0 ] );
- break;
- }
- }
- #endif
- void kbd_exit( int argc, char **argv ) {
- mb_exit( 0 );
- }
Comments