~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzleclient/vio.c

  • Committer: Monty Taylor
  • Date: 2009-03-25 21:06:47 UTC
  • mto: This revision was merged to the branch mainline in revision 964.
  • Revision ID: mordred@inaugust.com-20090325210647-7j1tm98gvct3jxsu
Removed legacy_db_type.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
  the file descriptior.
21
21
*/
22
22
 
23
 
#include "vio_priv.h"
 
23
#define DONT_MAP_VIO
 
24
#include <drizzled/global.h>
 
25
#include "vio.h"
 
26
#include <string.h>
 
27
#include <stdint.h>
24
28
 
25
29
/*
26
30
 * Helper to fill most of the Vio* with defaults.
27
31
 */
28
32
 
29
 
static void vio_init(Vio* vio, enum enum_vio_type type,
 
33
static void drizzleclient_vio_init(Vio* vio, enum enum_vio_type type,
30
34
                     int sd, uint32_t flags)
31
35
{
32
 
#ifndef HAVE_VIO_READ_BUFF
33
 
  flags&= ~VIO_BUFFERED_READ;
34
 
#endif
35
36
  memset(vio, 0, sizeof(*vio));
36
37
  vio->type     = type;
37
38
  vio->sd       = sd;
38
39
  if ((flags & VIO_BUFFERED_READ) &&
39
 
      !(vio->read_buffer= (char*)my_malloc(VIO_READ_BUFFER_SIZE, MYF(MY_WME))))
 
40
      !(vio->read_buffer= (char*)malloc(VIO_READ_BUFFER_SIZE)))
40
41
    flags&= ~VIO_BUFFERED_READ;
41
42
  {
42
 
    vio->viodelete      =vio_delete;
43
 
    vio->vioerrno       =vio_errno;
44
 
    vio->read= (flags & VIO_BUFFERED_READ) ? vio_read_buff : vio_read;
45
 
    vio->write          =vio_write;
46
 
    vio->fastsend       =vio_fastsend;
47
 
    vio->viokeepalive   =vio_keepalive;
48
 
    vio->should_retry   =vio_should_retry;
49
 
    vio->was_interrupted=vio_was_interrupted;
50
 
    vio->vioclose       =vio_close;
51
 
    vio->peer_addr      =vio_peer_addr;
52
 
    vio->vioblocking    =vio_blocking;
53
 
    vio->is_blocking    =vio_is_blocking;
54
 
    vio->timeout        =vio_timeout;
 
43
    vio->viodelete      =drizzleclient_vio_delete;
 
44
    vio->vioerrno       =drizzleclient_vio_errno;
 
45
    vio->read= (flags & VIO_BUFFERED_READ) ? drizzleclient_vio_read_buff : drizzleclient_vio_read;
 
46
    vio->write          =drizzleclient_vio_write;
 
47
    vio->fastsend       =drizzleclient_vio_fastsend;
 
48
    vio->viokeepalive   =drizzleclient_vio_keepalive;
 
49
    vio->should_retry   =drizzleclient_vio_should_retry;
 
50
    vio->was_interrupted=drizzleclient_vio_was_interrupted;
 
51
    vio->vioclose       =drizzleclient_vio_close;
 
52
    vio->peer_addr      =drizzleclient_vio_peer_addr;
 
53
    vio->vioblocking    =drizzleclient_vio_blocking;
 
54
    vio->is_blocking    =drizzleclient_vio_is_blocking;
 
55
    vio->timeout        =drizzleclient_vio_timeout;
55
56
  }
56
57
}
57
58
 
58
59
 
59
60
/* Reset initialized VIO to use with another transport type */
60
61
 
61
 
void vio_reset(Vio* vio, enum enum_vio_type type,
 
62
void drizzleclient_vio_reset(Vio* vio, enum enum_vio_type type,
62
63
               int sd, uint32_t flags)
63
64
{
64
65
  free(vio->read_buffer);
65
 
  vio_init(vio, type, sd, flags);
 
66
  drizzleclient_vio_init(vio, type, sd, flags);
66
67
}
67
68
 
68
69
 
69
70
/* Open the socket or TCP/IP connection and read the fnctl() status */
70
71
 
71
 
Vio *vio_new(int sd, enum enum_vio_type type, uint32_t flags)
 
72
Vio *drizzleclient_vio_new(int sd, enum enum_vio_type type, uint32_t flags)
72
73
{
73
 
  Vio *vio;
 
74
  Vio *vio = (Vio*) malloc(sizeof(Vio));
74
75
 
75
 
  if ((vio = (Vio*) my_malloc(sizeof(*vio),MYF(MY_WME))))
 
76
  if (vio != NULL)
76
77
  {
77
 
    vio_init(vio, type, sd, flags);
 
78
    drizzleclient_vio_init(vio, type, sd, flags);
78
79
    sprintf(vio->desc, "TCP/IP (%d)", vio->sd);
79
80
    /*
80
81
      We call fcntl() to set the flags and then immediately read them back
93
94
}
94
95
 
95
96
 
96
 
void vio_delete(Vio* vio)
 
97
void drizzleclient_vio_delete(Vio* vio)
97
98
{
98
99
  if (!vio)
99
100
    return; /* It must be safe to delete null pointers. */
110
111
  components below it when application finish
111
112
 
112
113
*/
113
 
void vio_end(void)
 
114
void drizzleclient_vio_end(void)
114
115
{
115
116
}