Skip to content

Question about websocket read/writes thread safety. #1941

@kujukuju

Description

@kujukuju

HI, I'm trying to figure out if it's thread safe to call mg_ws_write from a completely different thread than the thread doing the reads.

I read through a bunch of issues/questions here and my guess so far is that this is fine. It seems that the websocket send events fire on the poll event. Presumably, as long as I'm mg_ws_write ing from the same thread, I don't think it could have any async issues.

However, then I saw this comment:
#139 (comment)

  1. Would be any issues calling mg_ws_write without dealing with thread safety?

  2. I have a loop set up calling mg_poll with a 0 ms timeout. All packet reads into here get put into a circular buffer than I then access from my other thread safely.

If a read takes say, 2 milliseconds, I believe this would delay the actual tcp packet sending from my mg_ws_write by 2 milliseconds due to packet writes waiting on the poll event to be processed. I saw another issue here about waking up the manager in order to perform an immediate write but the referenced wakeup function no longer seems to exist.

Is there a way to wake up the manager to immediately send a ws packet without waiting on the next poll?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions