I have the following structs defined:
In gf.h:
typedef struct gfcrequest_t gfcrequest_t;
In gf.c:
typedef struct gfcrequest_t {
struct sockaddr_in saddr;
// ...
char *path; // <---- get here
gfstatus_t status;
void (*writefunc)(void*, size_t, void *);
// ...
} gfcrequest_t;
In gf_main.c
typedef struct wrequest_t {
long int msg_type;
char *message;
gfcrequest_t *gfr; // <---- from here
} wrequest_t;
I want to be able to access the path
member of the gfr
pointer on an instance of wrequest_t
.
I have the following:
wrequest_t *wrequest = malloc(sizeof(struct wrequest_t));
bzero(&wrequest, sizeof(wrequest));
gfcrequest_t *gfr = gfc_create(); // function returns a pointer to gfcrequest_t
// ... some pre-processing
wrequest->gfr = gfr; // pointer to pointer, is that correct?
// ... pass the wrequest to thread through message queue for processing
Then, in the thread I pop the request out of the queue and try to process it
wrequest_t *wrequest;
for (;;) {
if (msgrcv(msg_id, &wrequest, size_wrequest, MSG_TYPE, 0) == -1) {
perror("failed to receive work request");
return NULL;
}
fprintf(stderr, "message is %s\n", wrequest->message);
if (strncmp(wrequest->message,
SHUTDOWN_MESSAGE, strlen(SHUTDOWN_MESSAGE)) == 0) {
fprintf(stderr, "thread %lu is done\n", id);
break;
}
fprintf(stderr, "thread %lu would process %s\n", id, wrequest->gfr->path); // <---------------------- this line doesn't work
}
Compiler complains:\
cc -Wall --std=gnu99 -g -Wno-format-security -c -o gfclient_download.o gfclient_download.c
gfclient_download.c: In function ‘work’:
gfclient_download.c:125:71: error: dereferencing pointer to incomplete type
fprintf(stderr, "thread %lu would process %s\n", id, wrequest->gfr->path);
If I change the ->
by the .
it complains:
cc -Wall --std=gnu99 -g -Wno-format-security -c -o gfclient_download.o gfclient_download.c
gfclient_download.c: In function ‘work’:
gfclient_download.c:125:71: error: request for member ‘path’ in something not a structure or union
fprintf(stderr, "thread %lu would process %s\n", id, wrequest->gfr.path);
I'm a newbie in C as you can see... is there something obvious that I'm doing wrong? how to I get to path
from the wrequest_t
?