Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
jlib
Commits
02a6efaf
Commit
02a6efaf
authored
4 years ago
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix server crash
parent
9c549958
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
6 deletions
+20
-6
simple_libevent_server.cpp
jlib/net/simple_libevent_server.cpp
+20
-6
No files found.
jlib/net/simple_libevent_server.cpp
View file @
02a6efaf
...
...
@@ -349,17 +349,31 @@ bool simple_libevent_server::start(uint16_t port, std::string& msg)
const
struct
timeval
*
tv_out
=
event_base_init_common_timeout
(
impl
->
base
,
&
impl
->
tv
);
memcpy
(
&
impl
->
tv
,
tv_out
,
sizeof
(
struct
timeval
));
impl
->
workerThreadContexts
=
new
PrivateImpl
::
WorkerThreadContextPtr
[
threadNum_
];
for
(
int
i
=
0
;
i
<
threadNum_
;
i
++
)
{
impl
->
workerThreadContexts
[
i
]
=
(
new
PrivateImpl
::
WorkerThreadContext
(
name_
,
i
));
}
// fix
// wait till all worker thread's base is created
bool
all_created
=
false
;
while
(
!
all_created
)
{
all_created
=
true
;
for
(
int
i
=
0
;
i
<
threadNum_
;
i
++
)
{
if
(
!
impl
->
workerThreadContexts
[
i
]
->
base
)
{
all_created
=
false
;
break
;
}
}
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
100
));
}
impl
->
thread
=
std
::
thread
([
this
]()
{
JLOG_INFO
(
"{} listen thread started"
,
name_
.
data
());
event_base_dispatch
(
this
->
impl
->
base
);
JLOG_INFO
(
"{} listen thread exited"
,
name_
.
data
());
});
impl
->
workerThreadContexts
=
new
PrivateImpl
::
WorkerThreadContextPtr
[
threadNum_
];
for
(
int
i
=
0
;
i
<
threadNum_
;
i
++
)
{
impl
->
workerThreadContexts
[
i
]
=
(
new
PrivateImpl
::
WorkerThreadContext
(
name_
,
i
));
}
started_
=
true
;
return
true
;
}
while
(
0
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment