~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle-2.0/libdrizzle/conn.cc

  • Committer: Mark Atwood
  • Date: 2011-06-18 01:53:35 UTC
  • mfrom: (2318.5.40 refactor11)
  • Revision ID: me@mark.atwood.name-20110618015335-nxum0ocvpkljgf67
mergeĀ lp:~olafvdspek/drizzle/refactor11

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
 
71
71
drizzle_return_t drizzle_con_set_fd(drizzle_con_st *con, int fd)
72
72
{
73
 
  drizzle_return_t ret;
74
 
 
75
73
  con->fd= fd;
76
74
 
77
 
  ret= _con_setsockopt(con);
 
75
  drizzle_return_t ret= _con_setsockopt(con);
78
76
  if (ret != DRIZZLE_RETURN_OK)
79
77
    con->drizzle->last_errno= errno;
80
78
 
101
99
 
102
100
drizzle_return_t drizzle_con_set_events(drizzle_con_st *con, short events)
103
101
{
104
 
  drizzle_return_t ret;
105
 
 
106
102
  if ((con->events | events) == con->events)
107
103
    return DRIZZLE_RETURN_OK;
108
104
 
110
106
 
111
107
  if (con->drizzle->event_watch_fn != NULL)
112
108
  {
113
 
    ret= con->drizzle->event_watch_fn(con, con->events,
 
109
    drizzle_return_t ret= con->drizzle->event_watch_fn(con, con->events,
114
110
                                      con->drizzle->event_watch_context);
115
111
    if (ret != DRIZZLE_RETURN_OK)
116
112
    {
124
120
 
125
121
drizzle_return_t drizzle_con_set_revents(drizzle_con_st *con, short revents)
126
122
{
127
 
  drizzle_return_t ret;
128
 
 
129
123
  if (revents != 0)
130
124
    con->options|= DRIZZLE_CON_IO_READY;
131
125
 
138
132
  if (revents & POLLOUT && !(con->events & POLLOUT) &&
139
133
      con->drizzle->event_watch_fn != NULL)
140
134
  {
141
 
    ret= con->drizzle->event_watch_fn(con, con->events,
 
135
    drizzle_return_t ret= con->drizzle->event_watch_fn(con, con->events,
142
136
                                      con->drizzle->event_watch_context);
143
137
    if (ret != DRIZZLE_RETURN_OK)
144
138
    {
328
322
  uint32_t major;
329
323
  uint32_t minor;
330
324
  uint32_t version;
331
 
  const char *current;
332
325
  char *end;
333
326
 
334
 
  current= con->server_version;
 
327
  const char *current= con->server_version;
335
328
 
336
329
  major= (uint32_t)strtoul(current, &end, 10);
337
330
  current= end + 1;
788
781
      snprintf(port, NI_MAXSERV, "%u", DRIZZLE_DEFAULT_TCP_PORT);
789
782
    port[NI_MAXSERV-1]= 0;
790
783
 
 
784
    memset(&ai, 0, sizeof(ai));
791
785
    ai.ai_socktype= SOCK_STREAM;
792
786
    ai.ai_protocol= IPPROTO_TCP;
793
787
    ai.ai_flags = AI_PASSIVE;
820
814
  case DRIZZLE_CON_SOCKET_UDS:
821
815
    con->addrinfo_next= &(con->socket.uds.addrinfo);
822
816
    break;
823
 
 
824
 
  default:
825
 
    break;
826
817
  }
827
818
 
828
819
  drizzle_state_pop(con);
831
822
 
832
823
drizzle_return_t drizzle_state_connect(drizzle_con_st *con)
833
824
{
834
 
  int ret;
835
 
  drizzle_return_t dret;
836
 
 
837
825
  drizzle_log_debug(con->drizzle, "drizzle_state_connect");
838
826
 
839
827
  if (con->fd != -1)
861
849
    return DRIZZLE_RETURN_ERRNO;
862
850
  }
863
851
 
864
 
  dret= _con_setsockopt(con);
 
852
  drizzle_return_t dret= _con_setsockopt(con);
865
853
  if (dret != DRIZZLE_RETURN_OK)
866
854
  {
867
855
    con->drizzle->last_errno= errno;
870
858
 
871
859
  while (1)
872
860
  {
873
 
    ret= connect(con->fd, con->addrinfo_next->ai_addr,
874
 
                 con->addrinfo_next->ai_addrlen);
 
861
    int ret= connect(con->fd, con->addrinfo_next->ai_addr, con->addrinfo_next->ai_addrlen);
875
862
 
876
863
#ifdef _WIN32
877
864
    errno = WSAGetLastError();
943
930
 
944
931
drizzle_return_t drizzle_state_connecting(drizzle_con_st *con)
945
932
{
946
 
  drizzle_return_t ret;
947
 
 
948
933
  drizzle_log_debug(con->drizzle, "drizzle_state_connecting");
949
934
 
950
935
  while (1)
963
948
      return DRIZZLE_RETURN_OK;
964
949
    }
965
950
 
966
 
    ret= drizzle_con_set_events(con, POLLOUT);
 
951
    drizzle_return_t ret= drizzle_con_set_events(con, POLLOUT);
967
952
    if (ret != DRIZZLE_RETURN_OK)
968
953
      return ret;
969
954
 
979
964
drizzle_return_t drizzle_state_read(drizzle_con_st *con)
980
965
{
981
966
  drizzle_return_t ret;
982
 
  ssize_t read_size;
983
967
 
984
968
  drizzle_log_debug(con->drizzle, "drizzle_state_read");
985
969
 
1007
991
  {
1008
992
    size_t available_buffer= (size_t)DRIZZLE_MAX_BUFFER_SIZE -
1009
993
        ((size_t)(con->buffer_ptr - con->buffer) + con->buffer_size);
1010
 
    read_size = recv(con->fd, (char *)con->buffer_ptr + con->buffer_size,
 
994
    ssize_t read_size = recv(con->fd, (char *)con->buffer_ptr + con->buffer_size,
1011
995
                     available_buffer, 0);
1012
996
#ifdef _WIN32
1013
997
    errno = WSAGetLastError();
1109
1093
drizzle_return_t drizzle_state_write(drizzle_con_st *con)
1110
1094
{
1111
1095
  drizzle_return_t ret;
1112
 
  ssize_t write_size;
1113
1096
 
1114
1097
  drizzle_log_debug(con->drizzle, "drizzle_state_write");
1115
1098
 
1116
1099
  while (con->buffer_size != 0)
1117
1100
  {
1118
 
  
1119
 
    write_size = send(con->fd,(char *) con->buffer_ptr, con->buffer_size, 0);
 
1101
    ssize_t write_size = send(con->fd,(char *) con->buffer_ptr, con->buffer_size, 0);
1120
1102
 
1121
1103
#ifdef _WIN32
1122
1104
    errno = WSAGetLastError();