トップ «前の日記(2015-08-29) 最新 次の日記(2015-08-31)» 編集

ヨタの日々

2001|08|09|10|11|12|
2002|01|02|03|04|05|06|07|08|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|12|
2024|01|02|03|04|

2015-08-30 :-)

_ やったこと

1000 起床 && 部屋掃除

1200 おひる。そうめん

1215 NHK のど自慢を眺めるなど

1300 読書などしていた

2100 飯

_ [libevent][cdbiff][eject]libevent で cdbiff (動作未確認)

手元の VMWare には /var/mail/$HOME もないし CD-ROM ドライブもないので。

The libevent API provides a mechanism to execute a callback function when a specific event occurs on a file descriptor or after a timeout has been reached. Furthermore, libevent also support callbacks due to signals or regular timeouts.
Currently, libevent supports /dev/poll, kqueue(2), event ports, POSIX select(2), Windows select(), poll(2), and epoll(4). The internal event mechanism is completely independent of the exposed event API, and a simple update of libevent can provide new functionality without having to redesign the applications.

非同期 API を提供するよ、システムの /dev/poll とか kqueue とか隠蔽するのでユーザーは実装を気にしなくていいよ、移植性が高くなるよ、とのこと。

環境

% uname -rsm
NetBSD 7.99.21 i386

コードだけ

man 3 event_init より

The additional flag EV_PERSIST makes an
    event_add() persistent until event_del() has been called.

EV_PERSIST を指定するといちいち event_add しなおさなくていいそうだ。

#include <sys/time.h>
#include <event.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>

void handler( int fd, short event, void* arg )
{
  puts( __FUNCTION__ );
  system( "eject cd" );
}

int main( int ac, char** av )
{
  int fd;
  struct event ev;
  char* user = getenv( "USER" );
  char filename[ FILENAME_MAX ];

  snprintf( filename, strlen( filename ), "%s/%s", "/var/mail/", user );
  
  fd = open( filename, O_RDONLY );
  if( fd < 0 )
  {
    err( EXIT_FAILURE, "open fail: %s", filename );
    exit( EXIT_FAILURE );
  }
  
  event_init();
  event_set( &ev, fd, EV_READ | EV_PERSIST, handler, NULL );
  event_add( &ev, NULL );
  event_dispatch();
  return 0;
}

参考

_ 買い物

amazon

4839954747