webby icon indicating copy to clipboard operation
webby copied to clipboard

user_data pointer and design flaw

Open questor opened this issue 11 years ago • 1 comments

some more errors :)

  • first when you set the user_data pointer it will be overwritten in the reset_connection function which is not only called on a new incoming connection, but also in the serving state (see webby.c line 1191)
  • there's a problem in the design of webby in my usecase: I've written a monitoring component were the http-page opens a websocket to webby and my c-code sends new values every second (without more traffic generated from the webpage). but to be able to send values from the c-code to the client I need to give webby a connection pointer which isn't available. (the connection pointer is only given if for example something is sent from the client to the server and the websockets-received-callback it triggered). saving the connection pointer during a websocket connection callback isn't working because the connections are moved by the memmove when another connection is closed.

for my usecase I've made a work-a-round in webby to be able to search for a user_data pointer and returning the corresponding connection, it's working for me but that's not really a good design :) I'm not sure how to fix this issue, perhaps by introducing connection id's.

questor avatar Apr 04 '13 08:04 questor

Good point, hadn't thought about that when connections were moved/compacted. What about keeping a rolling sequence number (a connection id) and then we'd modulo into the connections array to see if it still has the same ID?

deplinenoise avatar Apr 05 '13 03:04 deplinenoise