Skip to content

Commit

Permalink
fixed #1621
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Nov 14, 2024
1 parent 20d8eb4 commit 1a27187
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
7 changes: 6 additions & 1 deletion SRTHaishinKit/Sources/SRTConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ public actor SRTConnection: NetworkConnection {
}

func send(_ data: Data) async {
await socket?.send(data)
switch mode {
case .caller:
await socket?.send(data)
case .listener:
await clients.first?.send(data)
}
}

func recv() {
Expand Down
26 changes: 15 additions & 11 deletions SRTHaishinKit/Sources/SRTSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,8 @@ final actor SRTSocket {
case SRTS_CONNECTING:
logger.trace("SRT Socket Connecting")
case SRTS_CONNECTED:
connected = true
let (stream, continuation) = AsyncStream<Data>.makeStream()
outputs = continuation
Task {
for await data in stream where connected {
_ = sendmsg2(data)
totalBytesOut += data.count
queueBytesOut -= data.count
}
}
logger.info("SRT Socket Connected")
didConnected()
case SRTS_BROKEN:
logger.warn("SRT Socket Broken")
close()
Expand Down Expand Up @@ -106,7 +97,7 @@ final actor SRTSocket {
status = srt_getsockstate(socket)
switch status {
case SRTS_CONNECTED:
connected = true
didConnected()
default:
break
}
Expand Down Expand Up @@ -185,6 +176,19 @@ final actor SRTSocket {
return srt_bstats(socket, &perf, 1)
}

private func didConnected() {
connected = true
let (stream, continuation) = AsyncStream<Data>.makeStream()
outputs = continuation
Task {
for await data in stream where connected {
_ = sendmsg2(data)
totalBytesOut += data.count
queueBytesOut -= data.count
}
}
}

private func makeSocketError() -> SRTError {
let error_message = String(cString: srt_getlasterror_str())
logger.error(error_message)
Expand Down

0 comments on commit 1a27187

Please sign in to comment.