173 while (NULL != (
sh =
h->sh_head))
176 if (NULL !=
sh->cont)
180 if (NULL !=
h->restart_task)
183 h->restart_task = NULL;
185 if (NULL !=
h->read_task)
190 if (NULL ==
h->helper_proc)
198 h->fh_to_helper = NULL;
214 if (NULL !=
h->helper_proc)
218 h->helper_proc = NULL;
220 if (NULL !=
h->read_task)
225 if (NULL !=
h->write_task)
228 h->write_task = NULL;
230 if (NULL !=
h->helper_in)
234 h->fh_to_helper = NULL;
236 if (NULL !=
h->helper_out)
239 h->helper_out = NULL;
240 h->fh_from_helper = NULL;
242 while (NULL != (
sh =
h->sh_head))
245 if (NULL !=
sh->cont)
266 if (NULL !=
h->restart_task)
269 h->restart_task = NULL;
306 _ (
"Error reading from `%s': %s\n"),
309 if (NULL !=
h->exp_cb)
311 h->exp_cb (
h->cb_cls);
329 "Got 0 bytes from helper `%s' (EOF)\n",
331 if (NULL !=
h->exp_cb)
333 h->exp_cb (
h->cb_cls);
347 "Got %u bytes from helper `%s'\n",
358 _ (
"Failed to parse inbound message from helper `%s'\n"),
360 if (NULL !=
h->exp_cb)
362 h->exp_cb (
h->cb_cls);
390 if ((
h->helper_in == NULL) || (
h->helper_out == NULL))
394 "out of file descriptors? try again later\n");
404 "Starting HELPER process `%s'\n",
419 if (NULL ==
h->helper_proc)
423 "failed to start process? try again later\n");
452 h->restart_task = NULL;
455 "Restarting helper with back-off %u\n",
484 h->binary_argv[c] = NULL;
489 h->retry_back_off = 0;
506 if (NULL !=
h->write_task)
509 h->write_task = NULL;
513 while (NULL != (
sh =
h->sh_head))
516 if (NULL !=
sh->cont)
523 for (c = 0;
h->binary_argv[c] != NULL; c++)
559 h->write_task = NULL;
560 if (NULL == (
sh =
h->sh_head))
565 buf = (
const char *)
sh->msg;
568 ntohs (
sh->msg->size) -
sh->wpos);
573 _ (
"Error writing to `%s': %s\n"),
576 if (NULL !=
h->exp_cb)
578 h->exp_cb (
h->cb_cls);
583 "Stopping and restarting helper task!\n");
594 "Transmitted %u bytes to %s\n",
598 if (
sh->wpos == ntohs (
sh->msg->size))
601 if (NULL !=
sh->cont)
605 if (NULL !=
h->sh_head)
624 if (NULL ==
h->fh_to_helper)
626 if ((
GNUNET_YES == can_drop) && (NULL !=
h->sh_head))
634 sh->cont_cls = cont_cls;
636 if (NULL ==
h->write_task)
665 if (NULL ==
h->sh_head)
668 h->write_task = NULL;
struct GNUNET_MessageHeader * msg
static int ret
Return value of the commandline.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static struct SolverHandle * sh
static struct GNUNET_SCHEDULER_Task * t
Main task.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close_end(struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end)
Closes one half of an interprocess channel.
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
@ GNUNET_DISK_PF_BLOCKING_RW
Configure both pipe ends for blocking operations if set.
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void GNUNET_HELPER_send_cancel(struct GNUNET_HELPER_SendHandle *sh)
Cancel a GNUNET_HELPER_send operation.
struct GNUNET_HELPER_SendHandle * GNUNET_HELPER_send(struct GNUNET_HELPER_Handle *h, const struct GNUNET_MessageHeader *msg, int can_drop, GNUNET_HELPER_Continuation cont, void *cont_cls)
Send an message to the helper.
struct GNUNET_HELPER_Handle * GNUNET_HELPER_start(int with_control_pipe, const char *binary_name, char *const binary_argv[], GNUNET_MessageTokenizerCallback cb, GNUNET_HELPER_ExceptionCallback exp_cb, void *cb_cls)
Starts a helper and begins reading from it.
enum GNUNET_GenericReturnValue GNUNET_HELPER_wait(struct GNUNET_HELPER_Handle *h)
Reap the helper process.
void(* GNUNET_HELPER_ExceptionCallback)(void *cls)
Callback that will be called when the helper process dies.
enum GNUNET_GenericReturnValue GNUNET_HELPER_kill(struct GNUNET_HELPER_Handle *h, int soft_kill)
Sends termination signal to the helper process.
void GNUNET_HELPER_stop(struct GNUNET_HELPER_Handle *h, int soft_kill)
Kills the helper, closes the pipe and frees the handle.
void(* GNUNET_HELPER_Continuation)(void *cls, enum GNUNET_GenericReturnValue result)
Continuation function.
void GNUNET_HELPER_destroy(struct GNUNET_HELPER_Handle *h)
Free's the resources occupied by the helper handle.
#define GNUNET_log(kind,...)
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
struct GNUNET_OS_Process * GNUNET_OS_start_process_vap(enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, char *const argv[])
Start a process.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
@ GNUNET_OS_INHERIT_STD_ERR
When this flag is set, the child process will inherit stderr of the parent.
@ GNUNET_OS_USE_PIPE_CONTROL
Should a pipe be used to send signals to the child?
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
int(* GNUNET_MessageTokenizerCallback)(void *cls, const struct GNUNET_MessageHeader *message)
Functions with this signature are called whenever a complete message is received by the tokenizer.
enum GNUNET_GenericReturnValue GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
static void helper_write(void *cls)
Write to the helper-process.
static void start_helper(struct GNUNET_HELPER_Handle *h)
Start the helper process.
static void restart_task(void *cls)
Restart the helper process.
static void helper_read(void *cls)
Read from the helper-process.
static void stop_helper(struct GNUNET_HELPER_Handle *h, int soft_kill)
Stop the helper process, we're closing down or had an error.
Handle used to access files (and pipes).
Handle used to manage a pipe.
The handle to a helper process.
GNUNET_HELPER_ExceptionCallback exp_cb
The exception callback.
unsigned int retry_back_off
Count start attempts to increase linear back off.
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
struct GNUNET_OS_Process * helper_proc
The process id of the helper.
int with_control_pipe
Does the helper support the use of a control pipe for signalling?
void * cb_cls
The closure for callbacks.
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
struct GNUNET_DISK_PipeHandle * helper_in
PipeHandle to receive data from the helper.
const struct GNUNET_DISK_FileHandle * fh_from_helper
FileHandle to receive data from the helper.
const struct GNUNET_DISK_FileHandle * fh_to_helper
FileHandle to send data to the helper.
struct GNUNET_SCHEDULER_Task * write_task
Task to read from the helper.
struct GNUNET_DISK_PipeHandle * helper_out
PipeHandle to send data to the helper.
struct GNUNET_SCHEDULER_Task * restart_task
Restart task.
char ** binary_argv
NULL-terminated list of command-line arguments.
struct GNUNET_MessageStreamTokenizer * mst
The Message-Tokenizer that tokenizes the messages coming from the helper.
struct GNUNET_SCHEDULER_Task * read_task
Task to read from the helper.
char * binary_name
Binary to run.
Entry in the queue of messages we need to transmit to the helper.
struct GNUNET_HELPER_SendHandle * prev
This is an entry in a DLL.
struct GNUNET_HELPER_SendHandle * next
This is an entry in a DLL.
struct GNUNET_HELPER_Handle * h
The handle to a helper process.
GNUNET_HELPER_Continuation cont
Function to call upon completion.
const struct GNUNET_MessageHeader * msg
Message to transmit (allocated at the end of this struct)
void * cont_cls
Closure to 'cont'.
unsigned int wpos
Current write position.
Handle to a message stream tokenizer.
Entry in list of pending tasks.
static void exp_cb(void *cls)
Callback called if there was an exception during execution of the helper.