PHP沙龙 - PHPSalon.com - Justin's Blog - Sofee.cn

世界其实很简单,复杂的是人;生活其实很轻松,沉重的是感情!

吴文龙ID:ezdevelop
266795次访问,排名207好友0人,关注者1
ezdevelop的文章
原创 156 篇
翻译 0 篇
转载 37 篇
评论 818 篇
Justin的公告
-------------------------
点击进入我的新BLOG
-------------------------
作者声明:本人专栏内的所有文章,除注明转载外均为本人原创,未经许可,严禁任何形式转载。
最近评论
csnxlsh:也发个给我咯
谢谢了!我的邮箱是csnxlsh@sohu.com
ryl:robots.txt只是对好的搜索引擎google ,baidu....等一些好的,才遵守的规则
对垃圾的搜索引擎还是没用啊
所以不用phpmyadmin管理才是主要
ryl:居然有这么活宝的人
怎么把phpmyadmin都传上去
还安全吗
gudai:我等得花儿也谢了。
gudai:四、后记

本文仅是一篇入门级文章,旨在带你进入 PHP 扩展开发的行列,本人也将陆续写些高级开发的文章,敬请期待。


-------------------
嘿嘿。这个陆续,嘿嘿。。。。
文章分类
收藏
    相册
    My Photos
    .Personal
    Justin's Tech Blog(RSS)
    My Alumni
    My Website
    Friend's Blog
    PHP/MySQL经验点滴
    大麦英语学习论坛
    速推网
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 Timer on Windows and Linux收藏

    新一篇: Ubuntu下读写NTFS分区格式文件 | 旧一篇: CVS server on Ubuntu 6.0.6

    1. Timer on Windows 

    Timer on Windows 

    #define WIN32_LEAN_AND_MEAN
    #include “windows.h”

    UINT tid;

    VOID CALLBACK TimerHandler(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime) {
     printf(”Timer called @ [%ld]\n”, dwTime);
    }

    static BOOL WINAPI SignalHandler(DWORD event) {
     switch (event) {
      case CTRL_C_EVENT:
      case CTRL_BREAK_EVENT:
       KillTimer((HWND)NULL, tid);
       // Notify not to call other handlers.
       return FALSE;
     }

        return TRUE;
    }

    int main(int argc, char **argv) {
     MSG msg;

     if (!SetConsoleCtrlHandler(SignalHandler, TRUE/*add*/)) {
      printf(”SetConsoleCtrlHandler error - %d”, GetLastError());
     }
     if (!(tid = SetTimer((HWND)NULL, 0, 1000, (TIMERPROC)TimerHandler))) {
      printf(”SetTimer error - %d”, GetLastError());
     }

     while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
      TranslateMessage(&msg); // translates virtual-key codes
      DispatchMessage(&msg); // dispatches message to window
     }
     // remove our handler from the list of handlers
     SetConsoleCtrlHandler(SignalHandler, FALSE);
    }

     

    2. Timer on Linux

    Timer on Linux

    #include “stdio.h”
    #include “unistd.h”
    #include “errno.h”
    #include “time.h”
    #include “sys/time.h”
    #include “signal.h”

    #define SIGTIMER (SIGRTMAX)

    static timer_t tid;

    timer_t SetTimer(int signo, int sec, int mode) {
     static struct sigevent sigev;
     static timer_t tid;
     static struct itimerspec itval;
     static struct itimerspec oitval;

     // Create the POSIX timer to generate signo
     sigev.sigev_notify = SIGEV_SIGNAL;
     sigev.sigev_signo = signo;
     sigev.sigev_value.sival_ptr = &tid;

     if (timer_create(CLOCK_REALTIME, &sigev, &tid) == 0) {
      itval.it_value.tv_sec = sec / 1000;
      itval.it_value.tv_nsec = (long)(sec % 1000) * (1000000L);

      if (mode == 1) {
       itval.it_interval.tv_sec = itval.it_value.tv_sec;
       itval.it_interval.tv_nsec = itval.it_value.tv_nsec;
      } else {
       itval.it_interval.tv_sec = 0;
       itval.it_interval.tv_nsec = 0;
      }

      if (timer_settime(tid, 0, &itval, &oitval) != 0) {
       perror(”time_settime error!”);
      }
     } else {
      perror(”timer_create error!”);
      return -1;
     }
     return tid;
    }

    void SignalHandler(int signo, siginfo_t* info, void* context) {
     if (signo == SIGTIMER) {
      struct timeval tv;
      time_t t;
      struct tm *tm;

      gettimeofday(&tv, NULL);
      t = tv.tv_sec;
      tm = localtime(&t);
      printf(”Timer called @ [%02d:%02d:%02d.%03d]\n”, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec / 1000);
     } else if (signo == SIGINT) {
      timer_delete(tid);
      perror(”Crtl+c cached!”);
      exit(1);  // exit if CRTL/C is issued
     }
    }

    int main(int argc, char **argv) {
     struct sigaction sigact;

     sigemptyset(&sigact.sa_mask);
     sigact.sa_flags = SA_SIGINFO;
     sigact.sa_sigaction = SignalHandler;
     // set up sigaction to catch signal
     if (sigaction(SIGTIMER, &sigact, NULL) == -1) {
      perror(”sigaction failed”);
      return -1;
     }

     // Establish a handler to catch CTRL+c and use it for exiting.
     sigaction(SIGINT, &sigact, NULL);
     
     tid = SetTimer(SIGTIMER, 1000, 1);
     
     // Loop forever.  The application will exit in the signal handler
     // when a SIGINT is issued (CRTL+c will do this).
     for(;;) pause();

     return 0;
    }

     

    发表于 @ 2006年07月08日 13:34:00|评论(loading...)|编辑

    新一篇: Ubuntu下读写NTFS分区格式文件 | 旧一篇: CVS server on Ubuntu 6.0.6

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © Justin