~ubuntu-branches/ubuntu/saucy/ncbi-tools6/saucy-proposed

« back to all changes in this revision

Viewing changes to connect/ncbi_connection.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2009-08-11 22:03:47 UTC
  • mfrom: (1.4.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090811220347-g4b6lzdvphvvbpiu
* New upstream release.
* debian/libncbi6.symbols: update accordingly.
* debian/control: clean up obsolete or redundant relationship declarations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: ncbi_connection.c,v 6.55 2008/11/19 16:34:48 kazimird Exp $
 
1
/* $Id: ncbi_connection.c,v 6.60 2009/07/28 13:04:32 kazimird Exp $
2
2
 * ===========================================================================
3
3
 *
4
4
 *                            PUBLIC DOMAIN NOTICE
46
46
 
47
47
/* Standard logging message
48
48
 */
49
 
#define CONN_LOG_EX(subcode, level, message, status)                \
50
 
  CORE_LOGF_X(subcode, level,                                       \
51
 
              ("%s (connector \"%s\", status \"%s\")", message,     \
52
 
               conn->meta.get_type                                  \
53
 
               ? conn->meta.get_type(conn->meta.c_get_type)         \
54
 
               : "Unknown", IO_StatusStr(status)))
55
 
 
56
 
#define CONN_LOG(subcode, level, descr)         \
57
 
    CONN_LOG_EX(subcode, level, descr, status)
 
49
#define CONN_LOG_EX(subcode, func_name, level, message, status)            \
 
50
  {                                                                        \
 
51
      const char* ststr = status ? IO_StatusStr((EIO_Status) status) : ""; \
 
52
      char stbuf[80];                                                      \
 
53
      if ((EIO_Status) status == eIO_Timeout  &&  timeout) {               \
 
54
          sprintf(stbuf, "%s[%u.%06u]", ststr,                             \
 
55
                  (unsigned int)(timeout->sec + timeout->usec / 1000000),  \
 
56
                  (unsigned int)               (timeout->usec % 1000000)); \
 
57
          assert(strlen(stbuf) < sizeof(stbuf));                           \
 
58
          ststr = stbuf;                                                   \
 
59
      }                                                                    \
 
60
      CORE_LOGF_X(subcode, level,                                          \
 
61
                  ("[CONN_" #func_name "(%s)]  %s%s%s",                    \
 
62
                   conn->meta.get_type                                     \
 
63
                   ? conn->meta.get_type(conn->meta.c_get_type)            \
 
64
                   : "Unknown", message,                                   \
 
65
                   ststr  &&  *ststr ? ": "  : "",                         \
 
66
                   ststr             ? ststr : ""));                       \
 
67
  }
 
68
 
 
69
#define CONN_LOG(s_c, f_n, lvl, msg)  CONN_LOG_EX(s_c, f_n, lvl, msg, status)
 
70
 
 
71
/* Standard macros to verify that the passed connection handle is not NULL
 
72
 * NB: "retval" must be either a valid EIO_Status or 0 (no status logged)
 
73
 */
 
74
#define CONN_NOT_NULL_EX(subcode, func_name, retval)                    \
 
75
  if (!conn) {                                                          \
 
76
      const STimeout* timeout = 0/*dummy*/;                             \
 
77
      CONN_LOG_EX(subcode, func_name, eLOG_Error,                       \
 
78
                  "NULL connection handle", retval);                    \
 
79
      assert(conn);                                                     \
 
80
      return retval;                                                    \
 
81
  }
 
82
 
 
83
#define CONN_NOT_NULL(s_c, f_n)  CONN_NOT_NULL_EX(s_c, f_n, eIO_InvalidArg)
58
84
 
59
85
#ifdef _DEBUG
60
 
#  define CONN_TRACE(descr)  CONN_LOG(0, eLOG_Trace, descr)
 
86
#  define CONN_TRACE(f_n, msg)   CONN_LOG(0, f_n, eLOG_Trace, msg)
61
87
#else
62
 
#  define CONN_TRACE(descr)  ((void) 0)
 
88
#  define CONN_TRACE(f_n, msg)   ((void) 0)
63
89
#endif /*_DEBUG*/
64
90
 
65
 
/* Standard macros to verify that the passed connection handle is not NULL
66
 
 */
67
 
#define CONN_NOT_NULL_EX(subcode, func_name, status)              \
68
 
    if (!conn) {                                                  \
69
 
      CORE_LOG_X(subcode, eLOG_Error, "CONN_" #func_name          \
70
 
                 "(conn, ...) -- NULL connection handle");        \
71
 
      assert(conn);                                               \
72
 
      return status;                                              \
73
 
  }
74
 
 
75
 
#define CONN_NOT_NULL(subcode, func_name)   \
76
 
  CONN_NOT_NULL_EX(subcode, func_name, eIO_InvalidArg)
77
 
 
78
91
 
79
92
/* Connection state
80
93
 */
144
157
(CONN      conn,
145
158
 CONNECTOR connector)
146
159
{
 
160
    const STimeout* timeout = 0/*dummy*/;
147
161
    CONNECTOR  x_conn = 0;
148
162
    EIO_Status status;
149
163
 
152
166
    /* check arg */
153
167
    if (!connector  &&  !conn->meta.list) {
154
168
        assert(conn->state == eCONN_Unusable);
155
 
        status = eIO_Unknown;
156
 
        CONN_LOG(2, eLOG_Error,
157
 
                 "[CONN_ReInit]  Cannot re-init empty connection with NULL");
 
169
        status = eIO_InvalidArg;
 
170
        CONN_LOG(2, ReInit, eLOG_Error,
 
171
                 "Cannot re-init empty connection with NULL");
158
172
        return status;
159
173
    }
160
174
 
172
186
        if (conn->state == eCONN_Open) {
173
187
            if (conn->meta.flush) {
174
188
                conn->meta.flush(conn->meta.c_flush,
175
 
                                 conn->c_timeout == kDefaultTimeout ?
176
 
                                 conn->meta.default_timeout : conn->c_timeout);
 
189
                                 conn->c_timeout == kDefaultTimeout
 
190
                                 ? conn->meta.default_timeout
 
191
                                 : conn->c_timeout);
177
192
            }
178
193
            if (conn->meta.close) {
179
194
                status = conn->meta.close(conn->meta.c_close,
181
196
                                          ? conn->meta.default_timeout
182
197
                                          : conn->c_timeout);
183
198
                if (status != eIO_Success) {
184
 
                    CONN_LOG(3, connector ? eLOG_Error : eLOG_Warning,
185
 
                             "[CONN_ReInit]  Cannot close current connection");
 
199
                    CONN_LOG(3, ReInit, connector ? eLOG_Error : eLOG_Warning,
 
200
                             "Cannot close current connection");
186
201
                    if (connector)
187
202
                        return status;
188
203
                }
196
211
                if (!x_conn->next  &&  x_conn == conn->meta.list)
197
212
                    break;
198
213
                status = eIO_Unknown;
199
 
                CONN_LOG(4, eLOG_Error,
200
 
                         "[CONN_ReInit]  Partial re-init not allowed");
 
214
                CONN_LOG(4, ReInit, eLOG_Error, "Partial re-init not allowed");
201
215
                return status;
202
216
            }
203
217
        }
227
241
static EIO_Status s_Open
228
242
(CONN conn)
229
243
{
 
244
    const STimeout* timeout;
230
245
    EIO_Status status;
231
246
 
232
247
    assert(conn->state == eCONN_Closed  &&  conn->meta.list != 0);
233
248
 
234
249
    /* call current connector's "OPEN" method */
235
 
    status = conn->meta.open
236
 
        ? conn->meta.open(conn->meta.c_open,
237
 
                          conn->o_timeout == kDefaultTimeout ?
238
 
                          conn->meta.default_timeout : conn->o_timeout)
239
 
        : eIO_NotSupported;
 
250
    if (conn->meta.open) {
 
251
        timeout = (conn->o_timeout == kDefaultTimeout
 
252
                   ? conn->meta.default_timeout
 
253
                   : conn->o_timeout);
 
254
        status = conn->meta.open(conn->meta.c_open, timeout);
 
255
    } else {
 
256
        status = eIO_NotSupported;
 
257
        timeout = 0/*dummy*/;
 
258
    }
240
259
 
241
260
    if (status != eIO_Success) {
242
 
        CONN_LOG(5, eLOG_Error, "[CONN_Open]  Cannot open connection");
 
261
        CONN_LOG(5, Open, eLOG_Error, "Failed to open connection");
243
262
        return status;
244
263
    }
245
264
 
272
291
 EIO_Event       event,
273
292
 const STimeout* timeout)
274
293
{
275
 
    EIO_Status status = eIO_Success;
 
294
    char errbuf[80];
276
295
 
277
296
    CONN_NOT_NULL(8, SetTimeout);
278
297
 
282
301
            if (&conn->oo_timeout != timeout)
283
302
                conn->oo_timeout = *timeout;
284
303
            conn->o_timeout  = &conn->oo_timeout;
285
 
        } else {
 
304
        } else
286
305
            conn->o_timeout  = timeout;
287
 
        }
288
306
        break;
289
307
    case eIO_Close:
290
308
        if (timeout  &&  timeout != kDefaultTimeout) {
291
309
            if (&conn->cc_timeout != timeout)
292
310
                conn->cc_timeout = *timeout;
293
311
            conn->c_timeout  = &conn->cc_timeout;
294
 
        } else {
 
312
        } else
295
313
            conn->c_timeout  = timeout;
296
 
        }
297
314
        break;
298
315
    case eIO_Read:
299
316
    case eIO_ReadWrite:
301
318
            if (&conn->rr_timeout != timeout)
302
319
                conn->rr_timeout = *timeout;
303
320
            conn->r_timeout  = &conn->rr_timeout;
304
 
        } else {
 
321
        } else
305
322
            conn->r_timeout  = timeout;
306
 
        }
307
323
        if (event != eIO_ReadWrite)
308
324
            break;
309
325
        /*FALLTHRU*/
312
328
            if (&conn->ww_timeout != timeout)
313
329
                conn->ww_timeout = *timeout;
314
330
            conn->w_timeout  = &conn->ww_timeout;
315
 
        } else {
 
331
        } else
316
332
            conn->w_timeout  = timeout;
317
 
        }
318
333
        break;
319
334
    default:
320
 
        status = eIO_InvalidArg;
321
 
        CONN_LOG(9, eLOG_Error,
322
 
                 "[CONN_SetTimeout]  Unknown event to set timeout for");
323
 
        assert(0);
324
 
        break;
 
335
        sprintf(errbuf, "Unknown event #%d to set timeout for", (int) event);
 
336
        CONN_LOG_EX(9, SetTimeout, eLOG_Error, errbuf, eIO_InvalidArg);
 
337
        return eIO_InvalidArg;
325
338
    }
326
339
 
327
 
    return status;
 
340
    return eIO_Success;
328
341
}
329
342
 
330
343
 
332
345
(CONN      conn,
333
346
 EIO_Event event)
334
347
{
 
348
    const STimeout* timeout;
 
349
    char errbuf[80];
 
350
 
335
351
    CONN_NOT_NULL_EX(10, GetTimeout, 0);
336
352
 
337
353
    switch (event) {
338
354
    case eIO_Open:
339
 
        return conn->o_timeout;
 
355
        timeout = conn->o_timeout;
 
356
        break;
340
357
    case eIO_ReadWrite:
341
 
        CONN_LOG_EX(11, eLOG_Warning,
342
 
                    "[CONN_GetTimeout]  ReadWrite timeout requested",
343
 
                    eIO_InvalidArg);
 
358
        timeout = 0/*dummy*/;
 
359
        CONN_LOG_EX(11, GetTimeout, eLOG_Warning,
 
360
                    "ReadWrite timeout requested", 0);
344
361
        /*FALLTHRU*/
345
362
    case eIO_Read:
346
 
        return conn->r_timeout;
 
363
        timeout = conn->r_timeout;
 
364
        break;
347
365
    case eIO_Write:
348
 
        return conn->w_timeout;
 
366
        timeout = conn->w_timeout;
 
367
        break;
349
368
    case eIO_Close:
350
 
        return conn->c_timeout;
 
369
        timeout = conn->c_timeout;
 
370
        break;
351
371
    default:
352
 
        CONN_LOG_EX(12, eLOG_Error,
353
 
                    "[CONN_GetTimeout]  Unknown event to get timeout for",
354
 
                    eIO_InvalidArg);
 
372
        timeout = 0;
 
373
        sprintf(errbuf, "Unknown event #%d to get timeout for", (int) event);
 
374
        CONN_LOG_EX(12, GetTimeout, eLOG_Error, errbuf, 0);
355
375
        assert(0);
356
376
        break;
357
377
    }
358
 
    return 0;
 
378
    return timeout;
359
379
}
360
380
 
361
381
 
368
388
 
369
389
    CONN_NOT_NULL(13, Wait);
370
390
 
371
 
    if (conn->state == eCONN_Unusable               ||
372
 
        (event != eIO_Read  &&  event != eIO_Write) ||
373
 
        timeout == kDefaultTimeout)
 
391
    if (conn->state == eCONN_Unusable                ||
 
392
        (event != eIO_Read  &&  event != eIO_Write)  ||
 
393
        timeout == kDefaultTimeout) {
374
394
        return eIO_InvalidArg;
 
395
    }
375
396
 
376
397
    /* perform open, if not opened yet */
377
398
    if (conn->state != eCONN_Open  &&  (status = s_Open(conn)) != eIO_Success)
388
409
        : eIO_NotSupported;
389
410
 
390
411
    if (status != eIO_Success) {
391
 
        if (status != eIO_Timeout) {
392
 
            CONN_LOG(14, eLOG_Error, event == eIO_Read
393
 
                     ? "[CONN_Wait]  Error waiting on read"
394
 
                     : "[CONN_Wait]  Error waiting on write");
395
 
        } else if (!timeout  ||  (timeout->sec | timeout->usec)) {
396
 
            CONN_LOG(15, eLOG_Warning, event == eIO_Read
397
 
                     ? "[CONN_Wait]  Read timed out"
398
 
                     : "[CONN_Wait]  Write timed out");
 
412
        static const char* kErrMsg[] = { "Read event failed",
 
413
                                         "Write event failed" };
 
414
        ELOG_Level level;
 
415
        switch (status) {
 
416
        case eIO_Timeout:
 
417
            if (!timeout)
 
418
                level = eLOG_Warning;
 
419
            else if (timeout->sec | timeout->usec)
 
420
                level = eLOG_Trace;
 
421
            else
 
422
                return status;
 
423
            break;
 
424
        case eIO_Closed:
 
425
            level = event == eIO_Read ? eLOG_Trace : eLOG_Error;
 
426
            break;
 
427
        case eIO_Interrupt:
 
428
            level = eLOG_Warning;
 
429
            break;
 
430
        default:
 
431
            level = eLOG_Error;
 
432
            break;
399
433
        }
 
434
        CONN_LOG(14, Wait, level, kErrMsg[event != eIO_Read]);
400
435
    }
401
436
    return status;
402
437
}
408
443
 size_t      size,
409
444
 size_t*     n_written)
410
445
{
411
 
    const STimeout* wto;
 
446
    const STimeout* timeout;
412
447
    EIO_Status status;
413
448
 
414
449
    assert(*n_written == 0);
415
450
 
416
451
    /* check if the write method is specified at all */
417
452
    if (!conn->meta.write) {
 
453
        timeout = 0/*dummy*/;
418
454
        status = eIO_NotSupported;
419
 
        CONN_LOG(16, eLOG_Error, "[CONN_Write]  Unable to write data");
 
455
        CONN_LOG(16, Write, eLOG_Error, "Cannot write data");
420
456
        return status;
421
457
    }
422
458
 
423
459
    /* call current connector's "WRITE" method */
424
 
    wto = (conn->w_timeout == kDefaultTimeout
425
 
           ? conn->meta.default_timeout : conn->w_timeout);
426
 
    status = conn->meta.write(conn->meta.c_write, buf, size, n_written, wto);
 
460
    timeout = (conn->w_timeout == kDefaultTimeout
 
461
               ? conn->meta.default_timeout
 
462
               : conn->w_timeout);
 
463
    status = conn->meta.write(conn->meta.c_write, buf, size,
 
464
                              n_written, timeout);
427
465
 
428
466
    if (status != eIO_Success) {
429
467
        if (*n_written) {
430
 
            CONN_TRACE("[CONN_Write]  Write error");
 
468
            CONN_TRACE(Write, "Write error");
431
469
            status = eIO_Success;
432
470
        } else if (size) {
433
471
            ELOG_Level level;
434
472
            if (status != eIO_Timeout  ||  conn->w_timeout == kDefaultTimeout)
435
473
                level = eLOG_Error;
436
 
            else if (wto  &&  (wto->sec | wto->usec))
 
474
            else if (timeout  &&  (timeout->sec | timeout->usec))
437
475
                level = eLOG_Warning;
438
476
            else
439
477
                level = eLOG_Trace;
440
 
            CONN_LOG(17, level, "[CONN_Write]  Cannot write data");
 
478
            CONN_LOG(17, Write, level, "Unable to write data");
441
479
        }
442
480
    }
443
481
    return status;
479
517
    *n_written = 0;
480
518
    if (size  &&  !buf)
481
519
        return eIO_InvalidArg;
 
520
 
482
521
    CONN_NOT_NULL(18, Write);
483
522
 
484
523
    if (conn->state == eCONN_Unusable)
509
548
    CONN_NOT_NULL(19, PushBack);
510
549
 
511
550
    if (conn->state != eCONN_Open)
512
 
        return eIO_InvalidArg;
 
551
        return eIO_Closed;
513
552
 
514
553
    return BUF_PushBack(&conn->buf, buf, size) ? eIO_Success : eIO_Unknown;
515
554
}
518
557
extern EIO_Status CONN_Flush
519
558
(CONN conn)
520
559
{
 
560
    const STimeout* timeout;
521
561
    EIO_Status status;
522
562
 
523
563
    CONN_NOT_NULL(20, Flush);
533
573
    /* call current connector's "FLUSH" method */
534
574
    if (!conn->meta.flush)
535
575
        return eIO_Success;
536
 
    status = conn->meta.flush(conn->meta.c_flush,
537
 
                              conn->w_timeout == kDefaultTimeout ?
538
 
                              conn->meta.default_timeout : conn->w_timeout);
 
576
    timeout = (conn->w_timeout == kDefaultTimeout
 
577
               ? conn->meta.default_timeout
 
578
               : conn->w_timeout);
 
579
    status = conn->meta.flush(conn->meta.c_flush, timeout);
 
580
 
539
581
    if (status != eIO_Success)
540
 
        CONN_LOG(21, eLOG_Warning, "[CONN_Flush]  Cannot flush data");
 
582
        CONN_LOG(21, Flush, eLOG_Warning, "Failed to flush");
541
583
    return status;
542
584
}
543
585
 
551
593
 size_t*     n_read,
552
594
 int/*bool*/ peek)
553
595
{
554
 
    const STimeout* rto;
 
596
    const STimeout* timeout;
555
597
    EIO_Status status;
556
598
 
557
599
    assert(*n_read == 0);
558
600
 
559
601
    /* check if the read method is specified at all */
560
602
    if (!conn->meta.read) {
 
603
        timeout = 0/*dummy*/;
561
604
        status = eIO_NotSupported;
562
 
        CONN_LOG(22, eLOG_Error, "[CONN_Read]  Unable to read data");
 
605
        CONN_LOG(22, Read, eLOG_Error, "Cannot read data");
563
606
        return status;
564
607
    }
565
608
 
566
609
    /* read data from the internal peek buffer, if any */
567
610
    if (size) {
568
 
        *n_read = peek
569
 
            ? BUF_Peek(conn->buf, buf, size) : BUF_Read(conn->buf, buf, size);
 
611
        *n_read = (peek
 
612
                   ? BUF_Peek(conn->buf, buf, size)
 
613
                   : BUF_Read(conn->buf, buf, size));
570
614
        if (*n_read == size)
571
615
            return eIO_Success;
572
616
        buf = (char*) buf + *n_read;
575
619
    /* read data from the connection */
576
620
    {{
577
621
        size_t x_read = 0;
578
 
        rto = (conn->r_timeout == kDefaultTimeout
579
 
               ? conn->meta.default_timeout : conn->r_timeout);
 
622
        timeout = (conn->r_timeout == kDefaultTimeout
 
623
                   ? conn->meta.default_timeout
 
624
                   : conn->r_timeout);
580
625
        /* call current connector's "READ" method */
581
626
        status = conn->meta.read(conn->meta.c_read, buf, size - *n_read,
582
 
                                 &x_read, rto);
 
627
                                 &x_read, timeout);
583
628
        *n_read += x_read;
584
629
 
585
630
        /* save data in the internal peek buffer */
586
631
        if (peek  &&  !BUF_Write(&conn->buf, buf, x_read)) {
587
 
            CONN_LOG_EX(32, eLOG_Error, "[CONN_Read]  Cannot save peek data",
588
 
                        eIO_Unknown);
 
632
            CONN_LOG_EX(32, Read, eLOG_Error,
 
633
                        "Cannot save peek data", 0);
589
634
        }
590
635
    }}
591
636
 
592
637
    if (status != eIO_Success) {
593
638
        if (*n_read) {
594
 
            CONN_TRACE("[CONN_Read]  Read error");
 
639
            CONN_TRACE(Read, "Read error");
595
640
            status = eIO_Success;
596
641
        } else if (size  &&  status != eIO_Closed) {
597
642
            ELOG_Level level;
598
643
            if (status != eIO_Timeout  ||  conn->r_timeout == kDefaultTimeout)
599
644
                level = eLOG_Error;
600
 
            else if (rto  &&  (rto->sec | rto->usec))
 
645
            else if (timeout  &&  (timeout->sec | timeout->usec))
601
646
                level = eLOG_Warning;
602
647
            else
603
648
                level = eLOG_Trace;
604
 
            CONN_LOG(23, level, "[CONN_Read]  Cannot read data");
 
649
            CONN_LOG(23, Read, level, "Unable to read data");
605
650
        }
606
651
    }
607
652
    return status;
627
672
        *n_read += x_read;
628
673
        if (*n_read == size  ||  status != eIO_Success)
629
674
            break;
630
 
        /* flush the unwritten output data (if any) */
 
675
        /* keep flushing unwritten output data (if any) */
631
676
        if (conn->meta.flush) {
632
677
            conn->meta.flush(conn->meta.c_flush,
633
 
                             conn->r_timeout == kDefaultTimeout ?
634
 
                             conn->meta.default_timeout : conn->r_timeout);
 
678
                             conn->r_timeout == kDefaultTimeout
 
679
                             ? conn->meta.default_timeout
 
680
                             : conn->r_timeout);
635
681
        }
636
682
    }
637
683
 
667
713
    /* flush the unwritten output data (if any) */
668
714
    if (conn->meta.flush) {
669
715
        conn->meta.flush(conn->meta.c_flush,
670
 
                         conn->r_timeout == kDefaultTimeout ?
671
 
                         conn->meta.default_timeout : conn->r_timeout);
 
716
                         conn->r_timeout == kDefaultTimeout
 
717
                         ? conn->meta.default_timeout
 
718
                         : conn->r_timeout);
672
719
    }
673
720
 
674
721
    /* now do read */
714
761
        /* flush the unwritten output data (if any) */
715
762
        if (conn->meta.flush) {
716
763
            conn->meta.flush(conn->meta.c_flush,
717
 
                             conn->r_timeout == kDefaultTimeout ?
718
 
                             conn->meta.default_timeout : conn->r_timeout);
 
764
                             conn->r_timeout == kDefaultTimeout
 
765
                             ? conn->meta.default_timeout
 
766
                             : conn->r_timeout);
719
767
        }
720
768
    }
721
769
 
741
789
            len++;
742
790
        }
743
791
        if (i < x_read  &&  !BUF_PushBack(&conn->buf, x_buf + i, x_read - i)) {
744
 
            CONN_LOG_EX(33, eLOG_Error,
745
 
                        "[CONN_ReadLine]  Cannot push extra data back",
746
 
                        eIO_Unknown);
 
792
            const STimeout* timeout = 0;
 
793
            CONN_LOG_EX(15, ReadLine, eLOG_Error,
 
794
                        "Cannot pushback extra data", 0);
747
795
        }
748
796
        if (done  ||  len >= size)
749
797
            break;
846
894
 FConnAsyncCleanup cleanup)
847
895
{
848
896
    EIO_Status status;
 
897
    const STimeout* timeout = 0/*dummy*/;
849
898
    CONNECTOR  x_connector = conn->connector;
850
899
    SConnectorAsyncHandler* x_data = &conn->async_data;
851
900
 
852
901
    CONN_NOT_NULL(29, WaitAsync);
853
902
 
854
903
    /* perform connect, if not connected yet */
855
 
    if (!conn->connected  &&  (status = s_Connect(conn)) != eIO_Success)
 
904
    if (!conn->connected  &&  (status = s_Open(conn)) != eIO_Success)
856
905
        return status;
857
906
 
858
907
    /* reset previous handler, cleanup its data */
859
908
    /* (call current connector's "WAIT_ASYNC" method with NULLs) */
860
 
    status = x_connector->vtable.wait_async ?
861
 
        x_connector->vtable.wait_async(x_connector->handle, 0, 0) :
862
 
        eIO_NotSupported;
 
909
    status = (x_connector->vtable.wait_async
 
910
              ? x_connector->vtable.wait_async(x_connector->handle, 0, 0)
 
911
              : eIO_NotSupported);
863
912
    if (status != eIO_Success) {
864
 
        CONN_LOG(30, eLOG_Error, "[CONN_WaitAsync]  Cannot reset handler");
 
913
        CONN_LOG(30, WaitAsync, eLOG_Error, "Cannot reset handler");
865
914
        return status;
866
915
    }
867
916
    if (x_data->cleanup)
880
929
    x_data->cleanup    = cleanup;
881
930
 
882
931
    status = x_connector->vtable.wait_async(x_connector->handle,
883
 
                                            s_ConnectorAsyncHandler, x_data);
884
 
    if (status != eIO_Success) {
885
 
        CONN_LOG(31, eLOG_Error, "[CONN_WaitAsync]  Cannot set new handler");
886
 
    }
 
932
                                            s_ConnectorAsyncHandler,
 
933
                                            x_data);
 
934
    if (status != eIO_Success)
 
935
        CONN_LOG(31, WaitAsync, eLOG_Error, "Cannot set new handler");
887
936
    return status;
888
937
}
889
938
#endif /* IMPLEMENTED__CONN_WaitAsync */