Skip to content

Commit c39578c

Browse files
committed
subscribe interface is invoked multiple times by the same client, no need to add epoll events repeatedly
1 parent 2f1940c commit c39578c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

pink/src/pink_pubsub.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ void PubSubThread::Subscribe(PinkConn *conn,
147147
const bool pattern,
148148
std::vector<std::pair<std::string, int>>* result) {
149149
int subscribed = ClientChannelSize(conn);
150+
bool exist = (subscribed != 0);
150151

151152
for (size_t i = 0; i < channels.size(); i++) {
152153
if (pattern) { // if pattern mode, register channel to map
@@ -184,15 +185,17 @@ void PubSubThread::Subscribe(PinkConn *conn,
184185
}
185186
}
186187

187-
{
188-
slash::WriteLock l(&rwlock_);
189-
conns_[conn->fd()] = conn;
190-
}
188+
if (!exist) {
189+
{
190+
slash::WriteLock l(&rwlock_);
191+
conns_[conn->fd()] = conn;
192+
}
191193

192-
{
193-
slash::MutexLock l(&mutex_);
194-
fd_queue_.push(conn->fd());
195-
write(notify_pfd_[1], "", 1);
194+
{
195+
slash::MutexLock l(&mutex_);
196+
fd_queue_.push(conn->fd());
197+
write(notify_pfd_[1], "", 1);
198+
}
196199
}
197200
}
198201

0 commit comments

Comments
 (0)