Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinuxSocket.Dispose throws if socket was not connected #407

Open
ArXen42 opened this issue Mar 28, 2024 · 1 comment
Open

LinuxSocket.Dispose throws if socket was not connected #407

ArXen42 opened this issue Mar 28, 2024 · 1 comment
Assignees
Labels
bug Linux Linux or BlueZ related

Comments

@ArXen42
Copy link

ArXen42 commented Mar 28, 2024

public static void Main(String[] args)
{
    var socket = new LinuxSocket();
    socket.Dispose();
}

results in:

Unhandled exception. System.Net.Sockets.SocketException (107): Transport endpoint is not connected
   at InTheHand.Net.Sockets.LinuxSocket.ThrowOnSocketError(Int32 result, Boolean throwOnDisconnected)
   at InTheHand.Net.Sockets.LinuxSocket.get_RemoteEndPoint()
   at InTheHand.Net.Sockets.LinuxSocket.get_Connected()
   at InTheHand.Net.Sockets.LinuxSocket.Dispose(Boolean disposing)
   at System.Net.Sockets.Socket.Dispose()

So far I don't see any obvious reason to not just call Close unconditionally in Dispose implementation instead of checking result of getpeername (called by RemoteEndPoint property, which then throws due to received error code).

@peterfoot
Copy link
Member

Good catch. If the _socket value is not zero we should close anyway to release resources. I've made the change and it'll be in the next release.

@peterfoot peterfoot added bug Linux Linux or BlueZ related labels Mar 28, 2024
@peterfoot peterfoot self-assigned this Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Linux Linux or BlueZ related
Projects
None yet
Development

No branches or pull requests

2 participants