aboutsummaryrefslogtreecommitdiff
path: root/src/consensus
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-12-06 13:53:33 +0000
committerChristian Grothoff <christian@grothoff.org>2012-12-06 13:53:33 +0000
commit4127ea5df52dafca5538d2f9b74b0bec0c18bb8d (patch)
tree09ecd26d65c0d5c639df6a8c285b6ccbc06d37ad /src/consensus
parenteb7221b4ca8db6152240b4f71b35ef7296795532 (diff)
downloadgnunet-4127ea5df52dafca5538d2f9b74b0bec0c18bb8d.tar.gz
gnunet-4127ea5df52dafca5538d2f9b74b0bec0c18bb8d.zip
-improving shutdown behavior
Diffstat (limited to 'src/consensus')
-rw-r--r--src/consensus/gnunet-consensus.c42
1 files changed, 16 insertions, 26 deletions
diff --git a/src/consensus/gnunet-consensus.c b/src/consensus/gnunet-consensus.c
index 12d0965e9..bc518657e 100644
--- a/src/consensus/gnunet-consensus.c
+++ b/src/consensus/gnunet-consensus.c
@@ -48,12 +48,6 @@ static struct GNUNET_DISK_FileHandle *stdin_fh;
48 */ 48 */
49static GNUNET_SCHEDULER_TaskIdentifier stdin_tid = GNUNET_SCHEDULER_NO_TASK; 49static GNUNET_SCHEDULER_TaskIdentifier stdin_tid = GNUNET_SCHEDULER_NO_TASK;
50 50
51/**
52 * Element currently being sent to the service
53 */
54static struct GNUNET_CONSENSUS_Element *element;
55
56
57 51
58static void 52static void
59stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 53stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
@@ -76,23 +70,22 @@ conclude_cb (void *cls,
76} 70}
77 71
78 72
79
80static void 73static void
81insert_done_cb (void *cls, 74insert_done_cb (void *cls,
82 int success) 75 int success)
83{ 76{
77 struct GNUNET_CONSENSUS_Element *element = cls;
78
79 GNUNET_free (element);
84 if (GNUNET_YES != success) 80 if (GNUNET_YES != success)
85 { 81 {
86 printf ("insert failed\n"); 82 printf ("insert failed\n");
87 GNUNET_SCHEDULER_shutdown (); 83 GNUNET_SCHEDULER_shutdown ();
84 return;
88 } 85 }
89
90 GNUNET_free (element);
91
92 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == stdin_tid); 86 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == stdin_tid);
93
94 stdin_tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdin_fh, 87 stdin_tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdin_fh,
95 &stdin_cb, NULL); 88 &stdin_cb, NULL);
96} 89}
97 90
98 91
@@ -107,10 +100,12 @@ stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
107{ 100{
108 char buf[1024]; 101 char buf[1024];
109 char *ret; 102 char *ret;
110 ret = fgets (buf, 1024, stdin); 103 struct GNUNET_CONSENSUS_Element *element;
111 104
112 stdin_tid = GNUNET_SCHEDULER_NO_TASK; 105 stdin_tid = GNUNET_SCHEDULER_NO_TASK;
113 106 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
107 return; /* we're done here */
108 ret = fgets (buf, 1024, stdin);
114 if (NULL == ret) 109 if (NULL == ret)
115 { 110 {
116 if (feof (stdin)) 111 if (feof (stdin))
@@ -118,10 +113,6 @@ stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118 printf ("concluding ...\n"); 113 printf ("concluding ...\n");
119 GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_FOREVER_REL, conclude_cb, NULL); 114 GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_FOREVER_REL, conclude_cb, NULL);
120 } 115 }
121 else
122 {
123 GNUNET_SCHEDULER_shutdown ();
124 }
125 return; 116 return;
126 } 117 }
127 118
@@ -131,11 +122,11 @@ stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
131 element->type = 0; 122 element->type = 0;
132 element->size = strlen(buf) + 1; 123 element->size = strlen(buf) + 1;
133 element->data = &element[1]; 124 element->data = &element[1];
134 strcpy((char *) &element[1], buf); 125 strcpy ((char *) &element[1], buf);
135 126 GNUNET_CONSENSUS_insert (consensus, element, &insert_done_cb, element);
136 GNUNET_CONSENSUS_insert (consensus, element, insert_done_cb, NULL);
137} 127}
138 128
129
139/** 130/**
140 * Called when a new element was received from another peer, or an error occured. 131 * Called when a new element was received from another peer, or an error occured.
141 * 132 *
@@ -157,6 +148,7 @@ cb (void *cls,
157 return GNUNET_YES; 148 return GNUNET_YES;
158} 149}
159 150
151
160/** 152/**
161 * Function run on shutdown to clean up. 153 * Function run on shutdown to clean up.
162 * 154 *
@@ -166,14 +158,12 @@ cb (void *cls,
166static void 158static void
167shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 159shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
168{ 160{
169
170 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "shutting down\n"); 161 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "shutting down\n");
171 if (NULL == consensus) 162 if (NULL != consensus)
172 { 163 {
173 return; 164 GNUNET_CONSENSUS_destroy (consensus);
165 consensus = NULL;
174 } 166 }
175
176 GNUNET_CONSENSUS_destroy (consensus);
177} 167}
178 168
179 169