| 43 | } |
| 44 | |
| 45 | bool queue_file::create(const char* home, const char* queueName, |
| 46 | const char* extName, unsigned width) |
| 47 | { |
| 48 | acl_assert(width > 0); |
| 49 | |
| 50 | struct timeval tv; |
| 51 | acl::string buf; |
| 52 | acl::fstream* fp = NULL; |
| 53 | int i = 0; |
| 54 | bool dir_exist; |
| 55 | |
| 56 | ACL_SAFE_STRNCPY(m_home, home, sizeof(m_home)); |
| 57 | ACL_SAFE_STRNCPY(m_queueName, queueName, sizeof(m_queueName)); |
| 58 | ACL_SAFE_STRNCPY(m_extName, extName, sizeof(m_extName)); |
| 59 | |
| 60 | unsigned int n; |
| 61 | |
| 62 | while (true) { |
| 63 | // ����������� |
| 64 | memset(&tv, 0, sizeof(tv)); |
| 65 | gettimeofday(&tv, NULL); |
| 66 | safe_snprintf(m_partName, sizeof(m_partName), |
| 67 | "%u_%lu_%08x_%08x_%u", |
| 68 | (unsigned int) getpid(), |
| 69 | (unsigned long) acl::thread::thread_self(), |
| 70 | (unsigned int) tv.tv_sec, |
| 71 | (unsigned int) tv.tv_usec, |
| 72 | (unsigned int) __counter); |
| 73 | if (__counter++ >= 1024000) { |
| 74 | __counter = 0; |
| 75 | } |
| 76 | |
| 77 | // ���������Ŀ¼ |
| 78 | n = queue_manager::hash_queueSub(m_partName, width); |
| 79 | safe_snprintf(m_queueSub, sizeof(m_queueSub), "%u", n); |
| 80 | |
| 81 | buf.clear(); |
| 82 | buf << m_home << PATH_SEP << m_queueName << PATH_SEP << m_queueSub |
| 83 | << PATH_SEP << m_partName << "." << extName; |
| 84 | |
| 85 | fp = NEW fstream; |
| 86 | |
| 87 | dir_exist = false; |
| 88 | |
| 89 | while (true) { |
| 90 | // �����Դ���Ψһ�ļ� |
| 91 | if (fp->open(buf.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600)) { |
| 92 | goto END; |
| 93 | } |
| 94 | |
| 95 | logger_warn("open file %s error(%s)", buf.c_str(), acl_last_serror()); |
| 96 | |
| 97 | if (last_error() != ENOENT || dir_exist) { |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | // �����Դ���Ŀ¼ |
| 102 | buf.clear(); |
no test coverage detected