MCPcopy Create free account
hub / github.com/acl-dev/acl / create

Method create

lib_acl_cpp/src/queue/queue_file.cpp:45–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45bool 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();

Callers 1

create_fileMethod · 0.45

Calls 12

safe_snprintfFunction · 0.85
thread_selfFunction · 0.85
acl_last_serrorFunction · 0.85
last_errorFunction · 0.85
acl_make_dirsFunction · 0.85
file_handleMethod · 0.80
gettimeofdayFunction · 0.50
sleepFunction · 0.50
last_serrorFunction · 0.50
clearMethod · 0.45
openMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected