Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: TcpSocket::disconnect()  (Read 2938 times)

0 Members and 1 Guest are viewing this topic.

quicksilver

  • Newbie
  • *
  • Posts: 7
    • View Profile
TcpSocket::disconnect()
« on: January 28, 2013, 04:19:19 pm »
I'm writing a network application and needed to know a little bit more about TcpSocket::disconnect() for sfml 2.0.
From the documentation we have:


Disconnect the socket from its remote peer.

This function gracefully closes the connection. If the socket is not connected, this function has no effect.

I wanted to know what exactly was going on under the hood here. I tried tracking it down in the source code but got stuck at SocketImpl::close(SocketHandle sock).

Specifically, does this function tell the socket's remote peer that this socket is disconnecting? Should I have to manually use the disconnect function on the remote peer's bound socket? (For example, application A has tcpSocket a bound to tcpSocket b residing in application B, if a uses .disconnect(), does b know this without me needing to send a packet of my own before disconnecting? Will this update b automatically?)
« Last Edit: January 28, 2013, 04:20:55 pm by quicksilver »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: TcpSocket::disconnect()
« Reply #1 on: January 28, 2013, 04:26:16 pm »
After socketA.disconnect(), any read or write operation on socketB will return sf::Socket::Disconnected. So yes, you will know that a disconnection occured without explicitely sending something.
Laurent Gomila - SFML developer

quicksilver

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: TcpSocket::disconnect()
« Reply #2 on: February 19, 2013, 09:25:49 pm »
Thanks for the help.
I had another question.

Are there any drawbacks from not using the disconnect function?
If the sockets on both ends were dynamically allocated and I delete them without calling disconnect, would this create any problems or memory leaks, would the hardware be left in an undesired state?

When I use disconnect on dynamically created sockets and then delete them (apparently while they are trying to do their thing with the other end of the connection) I get stack overflow issues. So I'm wondering if I can just delete them and ignore disconnect all together.

Thanks in advance.