~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to vio/vio.c

Removed/replaced DBUG symbols and standardized TRUE/FALSE

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