Skip to content
This repository was archived by the owner on Oct 21, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TouchPortalApi/Interfaces/IMessageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ namespace TouchPortalApi.Interfaces {
public delegate void ListChangeEventHandler(string actionId, string listId, string instanceId, string value);
public delegate void CloseEventHandler();
public delegate void ConnectEventHandler();
public delegate void ExitHandler();

public interface IMessageProcessor {
event ActionEventHandler OnActionEvent;
event ListChangeEventHandler OnListChangeEventHandler;
event CloseEventHandler OnCloseEventHandler;
event ConnectEventHandler OnConnectEventHandler;
event ExitHandler OnExitHandler;

Task Listen();
Task TryPairAsync();
Expand Down
5 changes: 5 additions & 0 deletions TouchPortalApi/MessageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Newtonsoft.Json;
using System;
using System.Buffers;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using TouchPortalApi.Configuration;
Expand All @@ -28,6 +29,7 @@ public class MessageProcessor : IMessageProcessor {
public event ListChangeEventHandler OnListChangeEventHandler;
public event CloseEventHandler OnCloseEventHandler;
public event ConnectEventHandler OnConnectEventHandler;
public event ExitHandler OnExitHandler;

#endregion

Expand Down Expand Up @@ -61,6 +63,9 @@ public async Task Listen() {
while (!_cancellationToken.IsCancellationRequested) {
try {
await _tPClient.ProcessPipes();
} catch (SocketException) {
OnExitHandler?.Invoke();
return;
} catch (Exception ex) {
Console.WriteLine(ex);
}
Expand Down
3 changes: 3 additions & 0 deletions TouchPortalApi/TPClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Buffers;
using System.IO.Pipelines;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -85,6 +86,8 @@ public async Task ProcessPipes() {
Task reading = ReadPipeAsync(pipe.Reader);

await Task.WhenAll(reading, writing).ConfigureAwait(false);
if(!_tpsocket.Connected)
throw new SocketException();
}

/// <summary>
Expand Down