Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define AUTH_SOCKET_ADDRESS "ipc://oauth2"
- #define AUTH_SUCCESS 0
- #define AUTH_FAILED 1
- #define AUTH_SOCK_FAILED 2
- #define AUTH_BIND_DAILED 3
- #define AUTH_SOME_OTHER 4
- struct core_buf {
- u_int8_t *data;
- u_int64_t length;
- u_int64_t offset;
- };
- struct http_request {
- u_int8_t method;
- u_int8_t flags;
- int status;
- u_int64_t start;
- u_int64_t end;
- u_int64_t total;
- char *query_string;
- };
- /* This is part of webserver code..see only nanomsg use case..for clarity I have provided
- the (part of)struct http_request definition too. */
- /* A web client send a request to my webserver, req holds the web client request.
- This method is trying to send the request query string to REP end-point...and the response
- from the REP end-point will send to web client as the response to the web client request. */
- int send_authentication_request(struct http_request* req)
- {
- int sock = nn_socket (AF_SP, NN_REQ);
- if(sock >= 0)
- {
- core_debug("send_authentication_request: sock created");
- if(nn_connect (sock, AUTH_SOCKET_ADDRESS) >= 0)
- {
- char *resp = NULL;
- int bytes = 0;
- int result;
- core_debug("'%s' connected with %s",AUTH_SOCKET_ADDRESS, req->query_string);
- result = nn_send (sock, req->query_string , strlen(req->query_string), 0);
- core_debug("nn_send result: %d",result); /* ***** This is successful */
- // Here its waiting for REP end-point reply, which its not getting...
- bytes = nn_recv (sock, &resp, NN_MSG, 0); /* ***** Waiting for response */
- core_debug("bytes received: %d",bytes);
- if(bytes > 0)
- {
- // send received data to the web client here...
- nn_freemsg (resp);
- }
- }
- else
- return AUTH_BIND_FAILED;
- }
- else
- return AUTH_SOCK_FAILED;
- return AUTH_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement