Skip to content

add WebSocket endpoint support#66

Open
heshammahamed wants to merge 8 commits into
mainfrom
Add/websocket_support
Open

add WebSocket endpoint support#66
heshammahamed wants to merge 8 commits into
mainfrom
Add/websocket_support

Conversation

@heshammahamed

Copy link
Copy Markdown
Contributor

No description provided.

* find all classes annotated with wsEndpoint modifier
* validate and extract the four handler functions (onConnect, onReady, onData, onClose)
* extract the URI from the modifier params to pass to setWebSocketHandler
* add wsConnection class with isDead flag and guarded send/close methods
* implement constructSocketConnectHandler to call user onConnect with raw connection ptr
* implement constructSocketReadyHandler to look up wsConnection and call user onReady
* implement constructSocketDataHandler with isBinary flag derived from opcode
* implement constructSocketCloseHandler to nullify connection, call user onClose, then remove from map
* add socketConnections map to track active connections by ptr[Http.Connection]
* Reference handlers by node pointer (Passage), not by name path
* Pass the function node to setWebSocketHandler, not its wrapping block
* Keep handler blocks alive across insertAst (avoid use-after-free)
* Use ArchInt (cast from connection ptr) as the socketConnections key
…f per-class

Previously, a single  annotated a class containing
one method per handler
Handlers are now declared individually, each with its own
 annotation on a standalone
function
…g string to ref -- map[String , ptr[TiObject]] -- .
Comment thread WebPlatform/server.alusus Outdated
socketUrlHandlers.setAt(hPos, handlersRef(index)~no_deref);
def element : ptr[Core.Basic.TiObject] = handlersRef(index)~ptr;

socketUrlHandlers.setAt(hPos, element);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Map.setAt fails when T2 is a ref[...] type

The bug is in this line inside setAt:

handler this.setAt(i: ArchInt, value: T2): ref[Map[T1, T2]] {
    if i < 0 || i >= this.keys.getLength() {
        System.fail(1, "Argument `i` is out of range.")
    }
    this.values(i) = value;
    return this
}

this.values(i) returns a ref[T2]. When T2 is itself a ref[...] type, plain = tries to write into whatever that reference currently points to — but if it doesn't point to anything valid yet, this fails/errors, since we need to specify the reference's target before we can assign through it see the Docs about References.

For now i changed my using for Map so instead have T2 as a ref[...] i switch to use ptr[...] data type untill you confirm if it is a real bug and we can see how to solve it.

i think about if we have the T2 is a ref[...] in Map then in the setAt we use ~no_deref operator on the this.value(i) so we make the refrence point to the given value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant