FreeBSD中基于ncurses的服务器状态监视器

几个要点

延迟刷新:

struct timeval pre_t;

inline void Refresh()

{

struct timeval cur_t;

gettimeofday( &cur_t, 0 );

if( (cur_t.tv_usec - pre_t.tv_usec ) > 1000*100 )

{

refresh();

pre_t = cur_t;

}

else if( ( cur_t.tv_sec - pre_t.tv_sec ) > 0 )

{

refresh();

pre_t = cur_t;

}

}

功能键获得:

////////////// VT100+

#define VT100+_KEY_F1 0x1b4f50

inline unsigned int getkey( char ch )

{

unsigned int res = ch;

char count=1;

timeout(0);

drawlock.LOCK();

while(ch = getch())

{

if(ch==-1) break;

res = res*256 + ch;

if( ++count > 4 ) continue;

}

drawlock.UNLOCK();

timeout(-1);

return res;

}

使用:key = getkey( getch() )

使用UNIX域:

unlink( sspath.c_str() ); /*server_socket*/

server_sockfd = socket (AF_UNIX, SOCK_STREAM, 0);

server_address.sun_family = AF_UNIX;

strcpy( server_address.sun_path, sspath.c_str() );

server_len = sizeof (server_address);

你可能感兴趣的:(FreeBSD中基于ncurses的服务器状态监视器)