Skip to content

Commit

Permalink
fix: remove repeated service calls
Browse files Browse the repository at this point in the history
  • Loading branch information
koraykoska committed Aug 17, 2023
1 parent 17574c0 commit d79bd24
Showing 1 changed file with 0 additions and 20 deletions.
20 changes: 0 additions & 20 deletions Sources/libwebsockets/WebsocketClientContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ internal final class WebsocketClientContext {
private let protocolsPointer: UnsafeMutablePointer<lws_protocols>
private let extensionsPointer: UnsafeMutablePointer<lws_extension>

private var repeatedServiceScheduleSourceTimer: DispatchSourceTimer? = nil

internal private(set) var context: OpaquePointer!

// See: https://stackoverflow.com/questions/61236195/create-a-weak-unsafemutablerawpointer?rq=3
Expand Down Expand Up @@ -190,27 +188,9 @@ internal final class WebsocketClientContext {

// Polling of Events, including connection success
scheduleServiceCall()

// Repeated service calls if necessary
repeatedServiceScheduleSourceTimer = DispatchSource.makeTimerSource(queue: writableQueue)
repeatedServiceScheduleSourceTimer?.schedule(deadline: .now(), repeating: .seconds(1))
repeatedServiceScheduleSourceTimer?.setEventHandler { [weak self] in
guard let self else {
return
}

if self.fastServiceExecutionCallbacks.withLockedValue({ $0.count }) > 0 ||
self.eventLoopExecutionCallbacks.withLockedValue({ $0.count }) > 0 {
self.forceCancelService()
}
}
repeatedServiceScheduleSourceTimer?.resume()
}

deinit {
// Stop repeated service timer
repeatedServiceScheduleSourceTimer?.cancel()

// Destroy context. User nullify necessary to prevent segfault in future callbacks.
ws_context_user_nullify(context)
lws_context_destroy(context)
Expand Down

0 comments on commit d79bd24

Please sign in to comment.