~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to vio/vio.c

  • Committer: Brian Aker
  • Date: 2008-07-14 03:04:13 UTC
  • mfrom: (77.1.90 codestyle)
  • Revision ID: brian@tangent.org-20080714030413-dpv6opb0eoy1rd3f
Merging Monty's code, I did remove error on compile though (since it does
not currently work because of sql_plugin.cc)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 */
28
28
 
29
29
static void vio_init(Vio* vio, enum enum_vio_type type,
30
 
                     int sd, uint32_t flags)
 
30
                     my_socket sd, HANDLE hPipe, uint flags)
31
31
{
32
32
#ifndef HAVE_VIO_READ_BUFF
33
33
  flags&= ~VIO_BUFFERED_READ;
34
34
#endif
35
 
  memset(vio, 0, sizeof(*vio));
 
35
  bzero((char*) vio, sizeof(*vio));
36
36
  vio->type     = type;
37
37
  vio->sd       = sd;
 
38
  vio->hPipe    = hPipe;
 
39
  vio->localhost= flags & VIO_LOCALHOST;
38
40
  if ((flags & VIO_BUFFERED_READ) &&
39
41
      !(vio->read_buffer= (char*)my_malloc(VIO_READ_BUFFER_SIZE, MYF(MY_WME))))
40
42
    flags&= ~VIO_BUFFERED_READ;
59
61
/* Reset initialized VIO to use with another transport type */
60
62
 
61
63
void vio_reset(Vio* vio, enum enum_vio_type type,
62
 
               int sd, uint32_t flags)
 
64
               my_socket sd, HANDLE hPipe, uint flags)
63
65
{
64
 
  free(vio->read_buffer);
65
 
  vio_init(vio, type, sd, flags);
 
66
  my_free(vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
 
67
  vio_init(vio, type, sd, hPipe, flags);
66
68
}
67
69
 
68
70
 
69
71
/* Open the socket or TCP/IP connection and read the fnctl() status */
70
72
 
71
 
Vio *vio_new(int sd, enum enum_vio_type type, uint32_t flags)
 
73
Vio *vio_new(my_socket sd, enum enum_vio_type type, uint flags)
72
74
{
73
75
  Vio *vio;
74
76
 
75
77
  if ((vio = (Vio*) my_malloc(sizeof(*vio),MYF(MY_WME))))
76
78
  {
77
 
    vio_init(vio, type, sd, flags);
78
 
    sprintf(vio->desc, "TCP/IP (%d)", vio->sd);
 
79
    vio_init(vio, type, sd, 0, flags);
 
80
    sprintf(vio->desc,
 
81
            (vio->type == VIO_TYPE_SOCKET ? "socket (%d)" : "TCP/IP (%d)"),
 
82
            vio->sd);
 
83
#if !defined(NO_FCNTL_NONBLOCK)
79
84
    /*
80
85
      We call fcntl() to set the flags and then immediately read them back
81
86
      to make sure that we and the system are in agreement on the state of
88
93
    */
89
94
    fcntl(sd, F_SETFL, 0);
90
95
    vio->fcntl_mode= fcntl(sd, F_GETFL);
 
96
#elif defined(HAVE_SYS_IOCTL_H)                 /* hpux */
 
97
    /* Non blocking sockets doesn't work good on HPUX 11.0 */
 
98
    (void) ioctl(sd,FIOSNBIO,0);
 
99
    vio->fcntl_mode &= ~O_NONBLOCK;
 
100
#endif
91
101
  }
92
102
  return vio;
93
103
}
100
110
 
101
111
  if (vio->type != VIO_CLOSED)
102
112
    vio->vioclose(vio);
103
 
  free((unsigned char*) vio->read_buffer);
104
 
  free((unsigned char*) vio);
 
113
  my_free((uchar*) vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
 
114
  my_free((uchar*) vio,MYF(0));
105
115
}
106
116
 
107
117