~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to vio/vio.c

  • Committer: Monty Taylor
  • Date: 2008-08-05 19:01:20 UTC
  • mto: (266.1.1 codestyle)
  • mto: This revision was merged to the branch mainline in revision 266.
  • Revision ID: monty@inaugust.com-20080805190120-tsuziqz2mfqcw7pe
Removed libmysyslt.la, made mysys a noinst_ and made everything use it. It's
not a standalone lib, there's no reason to pretend otherwise.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
  the file descriptior.
21
21
*/
22
22
 
23
 
#include "config.h"
24
 
 
25
 
#define DONT_MAP_VIO
26
 
#include "vio.h"
27
 
 
28
 
#include <fcntl.h>
29
 
 
30
 
#include <cstdio>
31
 
#include <cstring>
32
 
#include <cstdlib>
33
 
#include <memory>
34
 
 
35
 
using namespace std;
36
 
 
37
 
namespace drizzle_protocol
38
 
{
 
23
#include "vio_priv.h"
39
24
 
40
25
/*
41
26
 * Helper to fill most of the Vio* with defaults.
42
27
 */
43
28
 
44
 
static void drizzleclient_vio_init(Vio* vio, enum enum_vio_type type,
45
 
                     int sd, uint32_t flags)
 
29
static void vio_init(Vio* vio, enum enum_vio_type type,
 
30
                     my_socket sd, uint32_t flags)
46
31
{
 
32
#ifndef HAVE_VIO_READ_BUFF
 
33
  flags&= ~VIO_BUFFERED_READ;
 
34
#endif
47
35
  memset(vio, 0, sizeof(*vio));
48
36
  vio->type     = type;
49
37
  vio->sd       = sd;
50
38
  if ((flags & VIO_BUFFERED_READ) &&
51
 
      !(vio->read_buffer= (char*)malloc(VIO_READ_BUFFER_SIZE)))
 
39
      !(vio->read_buffer= (char*)my_malloc(VIO_READ_BUFFER_SIZE, MYF(MY_WME))))
52
40
    flags&= ~VIO_BUFFERED_READ;
53
41
  {
54
 
    vio->viodelete      =drizzleclient_vio_delete;
55
 
    vio->vioerrno       =drizzleclient_vio_errno;
56
 
    vio->read= (flags & VIO_BUFFERED_READ) ? drizzleclient_vio_read_buff : drizzleclient_vio_read;
57
 
    vio->write          =drizzleclient_vio_write;
58
 
    vio->fastsend       =drizzleclient_vio_fastsend;
59
 
    vio->viokeepalive   =drizzleclient_vio_keepalive;
60
 
    vio->should_retry   =drizzleclient_vio_should_retry;
61
 
    vio->was_interrupted=drizzleclient_vio_was_interrupted;
62
 
    vio->vioclose       =drizzleclient_vio_close;
63
 
    vio->peer_addr      =drizzleclient_vio_peer_addr;
64
 
    vio->vioblocking    =drizzleclient_vio_blocking;
65
 
    vio->is_blocking    =drizzleclient_vio_is_blocking;
66
 
    vio->timeout        =drizzleclient_vio_timeout;
 
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;
67
55
  }
68
56
}
69
57
 
70
58
 
71
59
/* Reset initialized VIO to use with another transport type */
72
60
 
73
 
void drizzleclient_vio_reset(Vio* vio, enum enum_vio_type type,
74
 
               int sd, uint32_t flags)
 
61
void vio_reset(Vio* vio, enum enum_vio_type type,
 
62
               my_socket sd, uint flags)
75
63
{
76
 
  free(vio->read_buffer);
77
 
  drizzleclient_vio_init(vio, type, sd, flags);
 
64
  my_free(vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
 
65
  vio_init(vio, type, sd, flags);
78
66
}
79
67
 
80
68
 
81
69
/* Open the socket or TCP/IP connection and read the fnctl() status */
82
70
 
83
 
Vio *drizzleclient_vio_new(int sd, enum enum_vio_type type, uint32_t flags)
 
71
Vio *vio_new(my_socket sd, enum enum_vio_type type, uint flags)
84
72
{
85
 
  Vio *vio = (Vio*) malloc(sizeof(Vio));
 
73
  Vio *vio;
86
74
 
87
 
  if (vio != NULL)
 
75
  if ((vio = (Vio*) my_malloc(sizeof(*vio),MYF(MY_WME))))
88
76
  {
89
 
    drizzleclient_vio_init(vio, type, sd, flags);
 
77
    vio_init(vio, type, sd, flags);
90
78
    sprintf(vio->desc, "TCP/IP (%d)", vio->sd);
91
79
    /*
92
80
      We call fcntl() to set the flags and then immediately read them back
105
93
}
106
94
 
107
95
 
108
 
void drizzleclient_vio_delete(Vio* vio)
 
96
void vio_delete(Vio* vio)
109
97
{
110
98
  if (!vio)
111
99
    return; /* It must be safe to delete null pointers. */
112
100
 
113
101
  if (vio->type != VIO_CLOSED)
114
102
    vio->vioclose(vio);
115
 
  free((unsigned char*) vio->read_buffer);
116
 
  free((unsigned char*) vio);
 
103
  my_free((uchar*) vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
 
104
  my_free((uchar*) vio, MYF(0));
117
105
}
118
106
 
119
107
 
122
110
  components below it when application finish
123
111
 
124
112
*/
125
 
void drizzleclient_vio_end(void)
126
 
{ }
127
 
 
128
 
} /* namespace drizzle_protocol */
 
113
void vio_end(void)
 
114
{
 
115
}