File tree 1 file changed +14
-4
lines changed
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 4
4
5
5
#include < filesystem>
6
6
#include < memory>
7
+ #include < random>
7
8
#include < thread>
8
9
#include < chrono>
9
10
@@ -171,10 +172,7 @@ class UnixSocketServerTest : public SocketServerTest {
171
172
std::unique_ptr<UnixSocketServer> server;
172
173
173
174
virtual SocketServer* createListeningServer () {
174
- char filename[L_tmpnam];
175
- if (!std::tmpnam (filename)) {
176
- throw std::runtime_error (" unable to create name for temporary file" );
177
- }
175
+ const std::string filename = std::filesystem::temp_directory_path () / randomString ();
178
176
server.reset (new UnixSocketServer (&protocolHandler));
179
177
server->listen (filename);
180
178
return server.get ();
@@ -183,6 +181,18 @@ class UnixSocketServerTest : public SocketServerTest {
183
181
virtual void destroyListeningServer () {
184
182
server.reset ();
185
183
}
184
+
185
+ private:
186
+ std::random_device rd{};
187
+ std::mt19937 gen{rd ()};
188
+ std::uniform_int_distribution<> distrib{0 , 15 };
189
+
190
+ std::string randomString () {
191
+ std::stringstream out{};
192
+ for (std::size_t i = 0 ; i < 16 ; i++)
193
+ out << std::hex << distrib (gen);
194
+ return out.str ();
195
+ }
186
196
};
187
197
188
198
/*
You can’t perform that action at this time.
0 commit comments