Commit 499d0702 499d07025f3c6713fa018f89d4b8b732c30ebad2 by Sergey Poznyakoff

(amd_pool_flush): New function.

(amd_close): Call amd_pool_flush()
and initialize amd data so that subsequent amd_open() works
properly.
(amd_destroy): Call amd_pool_flush.
1 parent 0d7af037
...@@ -105,6 +105,7 @@ static void _amd_message_delete __P((struct _amd_data *amd, ...@@ -105,6 +105,7 @@ static void _amd_message_delete __P((struct _amd_data *amd,
105 struct _amd_message *msg)); 105 struct _amd_message *msg));
106 static int amd_pool_open __P((struct _amd_message *mhm)); 106 static int amd_pool_open __P((struct _amd_message *mhm));
107 static int amd_pool_open_count __P((struct _amd_data *amd)); 107 static int amd_pool_open_count __P((struct _amd_data *amd));
108 static void amd_pool_flush (struct _amd_data *amd);
108 static struct _amd_message **amd_pool_lookup __P((struct _amd_message *mhm)); 109 static struct _amd_message **amd_pool_lookup __P((struct _amd_message *mhm));
109 110
110 static int amd_envelope_date __P((envelope_t envelope, char *buf, size_t len, 111 static int amd_envelope_date __P((envelope_t envelope, char *buf, size_t len,
...@@ -303,6 +304,7 @@ amd_destroy (mailbox_t mailbox) ...@@ -303,6 +304,7 @@ amd_destroy (mailbox_t mailbox)
303 if (!amd) 304 if (!amd)
304 return; 305 return;
305 306
307 amd_pool_flush (amd);
306 monitor_wrlock (mailbox->monitor); 308 monitor_wrlock (mailbox->monitor);
307 for (i = 0; i < amd->msg_count; i++) 309 for (i = 0; i < amd->msg_count; i++)
308 { 310 {
...@@ -340,8 +342,30 @@ amd_open (mailbox_t mailbox, int flags) ...@@ -340,8 +342,30 @@ amd_open (mailbox_t mailbox, int flags)
340 static int 342 static int
341 amd_close (mailbox_t mailbox) 343 amd_close (mailbox_t mailbox)
342 { 344 {
345 struct _amd_data *amd;
346 int i;
347
343 if (!mailbox) 348 if (!mailbox)
344 return MU_ERR_MBX_NULL; 349 return MU_ERR_MBX_NULL;
350
351 amd = mailbox->data;
352
353 /* Destroy all cached data */
354 amd_pool_flush (amd);
355 monitor_wrlock (mailbox->monitor);
356 for (i = 0; i < amd->msg_count; i++)
357 {
358 message_destroy (&amd->msg_array[i]->message, amd->msg_array[i]);
359 free (amd->msg_array[i]);
360 }
361 free (amd->msg_array);
362 amd->msg_array = NULL;
363
364 amd->msg_count = 0; /* number of messages in the list */
365 amd->msg_max = 0; /* maximum message buffer capacity */
366
367 amd->uidvalidity = 0;
368
345 return 0; 369 return 0;
346 } 370 }
347 371
...@@ -1124,6 +1148,21 @@ amd_pool_open (struct _amd_message *mhm) ...@@ -1124,6 +1148,21 @@ amd_pool_open (struct _amd_message *mhm)
1124 return 0; 1148 return 0;
1125 } 1149 }
1126 1150
1151 static void
1152 amd_pool_flush (struct _amd_data *amd)
1153 {
1154 int i;
1155
1156 for (i = amd->pool_first; i != amd->pool_last; )
1157 {
1158 if (amd->msg_pool[i])
1159 amd_message_stream_close (amd->msg_pool[i]);
1160 if (++i == MAX_OPEN_STREAMS)
1161 i = 0;
1162 }
1163 amd->pool_first = amd->pool_last = 0;
1164 }
1165
1127 /* Attach a stream to a given message structure. The latter is supposed 1166 /* Attach a stream to a given message structure. The latter is supposed
1128 to be already added to the open message pool. */ 1167 to be already added to the open message pool. */
1129 int 1168 int
......