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

Author Topic: sf::SocketTCP.Send() & sf::SocketTCP.Receive() Threadsaf  (Read 32874 times)

0 Members and 1 Guest are viewing this topic.

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
sf::SocketTCP.Send() & sf::SocketTCP.Receive() Threadsaf
« Reply #15 on: March 19, 2010, 04:42:15 pm »
The question is not why using Send and Receive on the same Socket : Everybody (As far as I know) use this.
The real question is why could you want to Receive and Send at the same time ?
Mindiell
----

Merakon

  • Newbie
  • *
  • Posts: 3
    • View Profile
sf::SocketTCP.Send() & sf::SocketTCP.Receive() Threadsaf
« Reply #16 on: March 19, 2010, 04:51:14 pm »
Quote from: "Mindiell"
The question is not why using Send and Receive on the same Socket : Everybody (As far as I know) use this.
The real question is why could you want to Receive and Send at the same time ?

The original poster and I don't necessarily want to Receive and Send at the same time, and the original poster pointed out that when he tried to protect them with a mutex he ran into a deadlock. This is because the Receive function was a blocking call, so if you lock a mutex before the blocking call and then the server never sends anything (let's say it's waiting for clients to send it information before it relays information down), you'll hit a deadlock on the mutex.

As with my previous post, I believe the best way to approach this is by using a non-blocking socket. However, I'm not a network coding expert and I don't know if a non-blocking socket is going to cause other problems that I'm not aware of at present.