镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Feature request- Adding in user data for access in callbacks #249

Closed

Description

@ahonkan

I find I have to use global variables to pass the header-complete, message-complete events etc. between the callback and the thread that is polling a socket for data. Can there be a void pointer in the parser struct that I can use to assign to my own structs so that I can use the callbacks to set particular values in my passed structure?

I could make my structure global and have the callbacks access the elements directly but that's not neat in a multi-threaded environment.

Thanks

Activity

  1. hissohathair commented on Jun 5, 2015

    @hissohathair

    Doesn't that already exists in the parser_data struct?

      http_parser parser;
      http_parser_init(&parser, HTTP_BOTH);
      parser.data = (void*)&your_struct;
  2. indutny commented on Jun 5, 2015

    @indutny
    Member

    Yeah, this is already present. Sorry!

  3. lberezy commented on Jun 28, 2015

    @lberezy
    Contributor

    Perhaps some more documentation is necessary on the usage of this as it definitely wasn't super clear from the read-me.

  4. indutny commented on Jun 28, 2015

    @indutny
    Member

    @lberezy this is very usual for C libraries, but if you feel like you want it - I'm absolutely fine with reviewing a Pull Request ;)

  5. lberezy commented on Jun 28, 2015

    @lberezy
    Contributor

    Definitely, I'll put something together.

    There's a specific use case that highlights this problem (passing thread local data between a thread and an asynchronous modelled object) - in fact it's the problem I was trying to work around and what lead me here. I hope to address this so others don't have the same problem, or worse, think "http-parser" doesn't play nice with threads, time to use a different library...

  6. lberezy commented on Jun 28, 2015

    @lberezy
    Contributor

    sent ;)

    #256

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions