uv_udp_send() function returns error code -22 which means UV_EINVAL












0














i have written this piece of code to send udp messege.



static void send_message(uv_udp_t* handle, const struct sockaddr* addr, char* message, unsigned int length){
uv_udp_send_t* send_req = (uv_udp_send_t*)malloc(sizeof(uv_udp_send_t));
memset(send_req, 0x0, sizeof(uv_udp_send_t));
uv_buf_t sndbuf = uv_buf_init(message, length);
int error = uv_udp_send(send_req, handle, (const struct uv_buf_t *)&sndbuf, 1, addr, on_send);
if(error < 0){
printf("!! error %sn", uv_strerror(error));
printf("error code = %dn", error);
}
}


Here is the main function that calls the above function --



int main(int argc, char** argv) {   

reply_delayed_t reply;
reply.code = 0xf;
reply.load = 7;
MAKE_BUFFER(wake_buffer, reply);

send_message(&dsocket_2, wakeup_client_addr, wake_buffer, SIZE_OF_WAKE_UP);
return 0;
}


There is no compilation error. But at run time on console i find that the function call has returned an error code -22 which says invalid arguments. Can anyone help me to sort this out?



Some details about the arguments passed in send_message() is stated below. i think i should mention these details.



The variables uv_udp_t dsocket_2 and const struct sockaddr* wakeup_client_addris defined in another file var.c and included in this file(wake.c) from a header file(serve_client.h).



var.c



#include <uv.h>
#include "serve_client.h"

const struct sockaddr* wakeup_client_addr = NULL;
uv_udp_t dsocket_2;


serve_client.h



#ifndef ServerClient_H
#define ServerClient_H
#include <uv.h>

extern const struct sockaddr* wakeup_client_addr;
extern uv_udp_t dsocket_2;
#endif


There are two files having a main function (server.c and wake.c) Both the files includes the header file mentioned above. i have created a single executable for wake.c and var.c. And there is another executable including file server.c and var.c.
In server.c binding of dsocket_2 is done and the variable wakeup_client_addr which was NULL at the beginning gets updated with some address which is the client address received in the on_recv callback function of server.c when server receives some udp packet from the client to its dsocket_2.
The executable of server.c is run first and it is working perfectly. Here i assume that whenever the server receives some packet on its dsocket_2 the variable wakeup_client_addr gets updated with the received client address and as dsocket_2 is also already bind, both can be accessed by the executable for wake.c on being run but i get the error code -22 from the uv_udp_send() function stating "invalid arguments".
I am confused that Whether or not the executable of wake.c gets to access the values of wakeup_client_addr and dsocket_2 that the server.c updates on it's execution?**










share|improve this question
























  • May be the problem is elsewhere, try printing handle, addr, message and length before calling uv_udp_send
    – Neel Basu
    Nov 14 '18 at 9:01
















0














i have written this piece of code to send udp messege.



static void send_message(uv_udp_t* handle, const struct sockaddr* addr, char* message, unsigned int length){
uv_udp_send_t* send_req = (uv_udp_send_t*)malloc(sizeof(uv_udp_send_t));
memset(send_req, 0x0, sizeof(uv_udp_send_t));
uv_buf_t sndbuf = uv_buf_init(message, length);
int error = uv_udp_send(send_req, handle, (const struct uv_buf_t *)&sndbuf, 1, addr, on_send);
if(error < 0){
printf("!! error %sn", uv_strerror(error));
printf("error code = %dn", error);
}
}


Here is the main function that calls the above function --



int main(int argc, char** argv) {   

reply_delayed_t reply;
reply.code = 0xf;
reply.load = 7;
MAKE_BUFFER(wake_buffer, reply);

send_message(&dsocket_2, wakeup_client_addr, wake_buffer, SIZE_OF_WAKE_UP);
return 0;
}


There is no compilation error. But at run time on console i find that the function call has returned an error code -22 which says invalid arguments. Can anyone help me to sort this out?



Some details about the arguments passed in send_message() is stated below. i think i should mention these details.



The variables uv_udp_t dsocket_2 and const struct sockaddr* wakeup_client_addris defined in another file var.c and included in this file(wake.c) from a header file(serve_client.h).



var.c



#include <uv.h>
#include "serve_client.h"

const struct sockaddr* wakeup_client_addr = NULL;
uv_udp_t dsocket_2;


serve_client.h



#ifndef ServerClient_H
#define ServerClient_H
#include <uv.h>

extern const struct sockaddr* wakeup_client_addr;
extern uv_udp_t dsocket_2;
#endif


There are two files having a main function (server.c and wake.c) Both the files includes the header file mentioned above. i have created a single executable for wake.c and var.c. And there is another executable including file server.c and var.c.
In server.c binding of dsocket_2 is done and the variable wakeup_client_addr which was NULL at the beginning gets updated with some address which is the client address received in the on_recv callback function of server.c when server receives some udp packet from the client to its dsocket_2.
The executable of server.c is run first and it is working perfectly. Here i assume that whenever the server receives some packet on its dsocket_2 the variable wakeup_client_addr gets updated with the received client address and as dsocket_2 is also already bind, both can be accessed by the executable for wake.c on being run but i get the error code -22 from the uv_udp_send() function stating "invalid arguments".
I am confused that Whether or not the executable of wake.c gets to access the values of wakeup_client_addr and dsocket_2 that the server.c updates on it's execution?**










share|improve this question
























  • May be the problem is elsewhere, try printing handle, addr, message and length before calling uv_udp_send
    – Neel Basu
    Nov 14 '18 at 9:01














0












0








0







i have written this piece of code to send udp messege.



static void send_message(uv_udp_t* handle, const struct sockaddr* addr, char* message, unsigned int length){
uv_udp_send_t* send_req = (uv_udp_send_t*)malloc(sizeof(uv_udp_send_t));
memset(send_req, 0x0, sizeof(uv_udp_send_t));
uv_buf_t sndbuf = uv_buf_init(message, length);
int error = uv_udp_send(send_req, handle, (const struct uv_buf_t *)&sndbuf, 1, addr, on_send);
if(error < 0){
printf("!! error %sn", uv_strerror(error));
printf("error code = %dn", error);
}
}


Here is the main function that calls the above function --



int main(int argc, char** argv) {   

reply_delayed_t reply;
reply.code = 0xf;
reply.load = 7;
MAKE_BUFFER(wake_buffer, reply);

send_message(&dsocket_2, wakeup_client_addr, wake_buffer, SIZE_OF_WAKE_UP);
return 0;
}


There is no compilation error. But at run time on console i find that the function call has returned an error code -22 which says invalid arguments. Can anyone help me to sort this out?



Some details about the arguments passed in send_message() is stated below. i think i should mention these details.



The variables uv_udp_t dsocket_2 and const struct sockaddr* wakeup_client_addris defined in another file var.c and included in this file(wake.c) from a header file(serve_client.h).



var.c



#include <uv.h>
#include "serve_client.h"

const struct sockaddr* wakeup_client_addr = NULL;
uv_udp_t dsocket_2;


serve_client.h



#ifndef ServerClient_H
#define ServerClient_H
#include <uv.h>

extern const struct sockaddr* wakeup_client_addr;
extern uv_udp_t dsocket_2;
#endif


There are two files having a main function (server.c and wake.c) Both the files includes the header file mentioned above. i have created a single executable for wake.c and var.c. And there is another executable including file server.c and var.c.
In server.c binding of dsocket_2 is done and the variable wakeup_client_addr which was NULL at the beginning gets updated with some address which is the client address received in the on_recv callback function of server.c when server receives some udp packet from the client to its dsocket_2.
The executable of server.c is run first and it is working perfectly. Here i assume that whenever the server receives some packet on its dsocket_2 the variable wakeup_client_addr gets updated with the received client address and as dsocket_2 is also already bind, both can be accessed by the executable for wake.c on being run but i get the error code -22 from the uv_udp_send() function stating "invalid arguments".
I am confused that Whether or not the executable of wake.c gets to access the values of wakeup_client_addr and dsocket_2 that the server.c updates on it's execution?**










share|improve this question















i have written this piece of code to send udp messege.



static void send_message(uv_udp_t* handle, const struct sockaddr* addr, char* message, unsigned int length){
uv_udp_send_t* send_req = (uv_udp_send_t*)malloc(sizeof(uv_udp_send_t));
memset(send_req, 0x0, sizeof(uv_udp_send_t));
uv_buf_t sndbuf = uv_buf_init(message, length);
int error = uv_udp_send(send_req, handle, (const struct uv_buf_t *)&sndbuf, 1, addr, on_send);
if(error < 0){
printf("!! error %sn", uv_strerror(error));
printf("error code = %dn", error);
}
}


Here is the main function that calls the above function --



int main(int argc, char** argv) {   

reply_delayed_t reply;
reply.code = 0xf;
reply.load = 7;
MAKE_BUFFER(wake_buffer, reply);

send_message(&dsocket_2, wakeup_client_addr, wake_buffer, SIZE_OF_WAKE_UP);
return 0;
}


There is no compilation error. But at run time on console i find that the function call has returned an error code -22 which says invalid arguments. Can anyone help me to sort this out?



Some details about the arguments passed in send_message() is stated below. i think i should mention these details.



The variables uv_udp_t dsocket_2 and const struct sockaddr* wakeup_client_addris defined in another file var.c and included in this file(wake.c) from a header file(serve_client.h).



var.c



#include <uv.h>
#include "serve_client.h"

const struct sockaddr* wakeup_client_addr = NULL;
uv_udp_t dsocket_2;


serve_client.h



#ifndef ServerClient_H
#define ServerClient_H
#include <uv.h>

extern const struct sockaddr* wakeup_client_addr;
extern uv_udp_t dsocket_2;
#endif


There are two files having a main function (server.c and wake.c) Both the files includes the header file mentioned above. i have created a single executable for wake.c and var.c. And there is another executable including file server.c and var.c.
In server.c binding of dsocket_2 is done and the variable wakeup_client_addr which was NULL at the beginning gets updated with some address which is the client address received in the on_recv callback function of server.c when server receives some udp packet from the client to its dsocket_2.
The executable of server.c is run first and it is working perfectly. Here i assume that whenever the server receives some packet on its dsocket_2 the variable wakeup_client_addr gets updated with the received client address and as dsocket_2 is also already bind, both can be accessed by the executable for wake.c on being run but i get the error code -22 from the uv_udp_send() function stating "invalid arguments".
I am confused that Whether or not the executable of wake.c gets to access the values of wakeup_client_addr and dsocket_2 that the server.c updates on it's execution?**







c networking udp libuv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 7:29









Neel Basu

7,3991058117




7,3991058117










asked Nov 13 '18 at 5:24









Akash ChowdhuryAkash Chowdhury

11




11












  • May be the problem is elsewhere, try printing handle, addr, message and length before calling uv_udp_send
    – Neel Basu
    Nov 14 '18 at 9:01


















  • May be the problem is elsewhere, try printing handle, addr, message and length before calling uv_udp_send
    – Neel Basu
    Nov 14 '18 at 9:01
















May be the problem is elsewhere, try printing handle, addr, message and length before calling uv_udp_send
– Neel Basu
Nov 14 '18 at 9:01




May be the problem is elsewhere, try printing handle, addr, message and length before calling uv_udp_send
– Neel Basu
Nov 14 '18 at 9:01












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274328%2fuv-udp-send-function-returns-error-code-22-which-means-uv-einval%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274328%2fuv-udp-send-function-returns-error-code-22-which-means-uv-einval%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()