A simple way to wait for a timeout wait for the supermarket to realize

Source: Internet
Author: User
#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #define Max_ PATH 2048 #define TMP_RUN_PATH "/tmp/run" #define Wait_timeout_max 10000U//10 s Econds #define TEST_NAME "test_name"//parameter NAME #define RET_FALSE 0 #define Ret_t
    RUE 1 bool i_test_wait (const svpchar* name, SVPUint32 timeout) {bool Service_ready = Ret_false;
    Char Service_registry[max_path] = {0};

    snprintf (Service_registry, MAX_PATH, "%s/service/registry/%s", Tmp_run_path, name);

    if (Timeout > Wait_timeout_max) timeout = Wait_timeout_max;

    int try_time = TIMEOUT/50;
            while (try_time--) {if (svpfile::fileexist (service_registry) = = Ret_false) {sleep (50);
        Continue
        } Service_ready = Ret_true;
    Break
return service_ready; }
    /**************************** Source: Access (Pfilepath, F_OK);
    * int m_hfile =-1;
    * m_hfile = open (Pfilepath, o_creat);
    * Close (M_hfile);
    * Remove (filename); *************************************/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.