static const struct GNUNET_CONFIGURATION_Handle *config;
static GNUNET_SCHEDULER_TaskIdentifier abort_task;
-static GNUNET_SCHEDULER_TaskIdentifier test_task;
static GNUNET_SCHEDULER_TaskIdentifier read_task;
static GNUNET_SCHEDULER_TaskIdentifier write_task;
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_STREAM_close (peer1.socket);
+ if (NULL != peer1.socket)
+ GNUNET_STREAM_close (peer1.socket);
if (NULL != peer2.socket)
GNUNET_STREAM_close (peer2.socket);
if (NULL != peer2_listen_socket)
GNUNET_STREAM_listen_close (peer2_listen_socket); /* Close listen socket */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n");
- if (0 != abort_task)
- {
+ if (GNUNET_SCHEDULER_NO_TASK != abort_task)
GNUNET_SCHEDULER_cancel (abort_task);
- }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n");
GNUNET_SCHEDULER_shutdown ();
}
do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n");
- if (0 != test_task)
- {
- GNUNET_SCHEDULER_cancel (test_task);
- }
- if (0 != read_task)
- {
+ if (GNUNET_SCHEDULER_NO_TASK != read_task)
GNUNET_SCHEDULER_cancel (read_task);
- }
result = GNUNET_SYSERR;
- abort_task = 0;
+ abort_task = GNUNET_SCHEDULER_NO_TASK;
do_shutdown (cls, tc);
}
peer = (struct PeerData *) cls;
GNUNET_assert (GNUNET_STREAM_OK == status);
- GNUNET_assert (size < DATA_SIZE);
+ GNUNET_assert (size <= DATA_SIZE);
peer->bytes_wrote += size;
if (peer->bytes_wrote < DATA_SIZE) /* Have more data to send */
peer->io_write_handle =
GNUNET_STREAM_write (peer->socket,
((void *) data) + peer->bytes_wrote,
- DATA_SIZE - peer->bytes_wrote,
+ sizeof (data) - peer->bytes_wrote,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 5),
&write_completion,
LOG (GNUNET_ERROR_TYPE_DEBUG, "Generation of random data complete\n");
peer->io_write_handle = GNUNET_STREAM_write (peer->socket,
data,
- DATA_SIZE,
+ sizeof (data),
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 10),
&write_completion,
struct GNUNET_STREAM_Socket *socket,
const struct GNUNET_PeerIdentity *initiator)
{
+ if ((NULL == socket) || (NULL == initiator))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Binding error\n");
+ if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+ GNUNET_SCHEDULER_cancel (abort_task);
+ abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+ return GNUNET_OK;
+ }
GNUNET_assert (NULL != socket);
GNUNET_assert (socket != peer1.socket);
peer->socket = GNUNET_STREAM_open (config,
&peer2.self, /* Null for local peer? */
10, /* App port */
- &stream_open_cb,
- &peer1,
+ &stream_open_cb, &peer1,
+ GNUNET_STREAM_OPTION_MAX_PAYLOAD_SIZE, 500,
GNUNET_STREAM_OPTION_END);
GNUNET_assert (NULL != peer->socket);
}