~linuxjedi/drizzle/drizzle-couple-of-fixes

« back to all changes in this revision

Viewing changes to libdrizzle/state.c

  • Committer: Monty Taylor
  • Date: 2010-08-20 15:05:54 UTC
  • mfrom: (1720.1.7 build)
  • Revision ID: mordred@inaugust.com-20100820150554-fuwf8zs8qpzhpx6y
Added libdrizzle to the tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Drizzle Client & Protocol Library
 
3
 *
 
4
 * Copyright (C) 2008 Eric Day (eday@oddments.org)
 
5
 * All rights reserved.
 
6
 *
 
7
 * Use and distribution licensed under the BSD license.  See
 
8
 * the COPYING file in this directory for full text.
 
9
 */
 
10
 
 
11
/**
 
12
 * @file
 
13
 * @brief State machine definitions
 
14
 */
 
15
 
 
16
#include "common.h"
 
17
 
 
18
drizzle_return_t drizzle_state_loop(drizzle_con_st *con)
 
19
{
 
20
  drizzle_return_t ret;
 
21
 
 
22
  while (!drizzle_state_none(con))
 
23
  {
 
24
    ret= con->state_stack[con->state_current - 1](con);
 
25
    if (ret != DRIZZLE_RETURN_OK)
 
26
    {
 
27
      if (ret != DRIZZLE_RETURN_IO_WAIT && ret != DRIZZLE_RETURN_PAUSE &&
 
28
          ret != DRIZZLE_RETURN_ERROR_CODE)
 
29
      {
 
30
        drizzle_con_close(con);
 
31
      }
 
32
 
 
33
      return ret;
 
34
    }
 
35
  }
 
36
 
 
37
  return DRIZZLE_RETURN_OK;
 
38
}
 
39
 
 
40
drizzle_return_t drizzle_state_packet_read(drizzle_con_st *con)
 
41
{
 
42
  drizzle_log_debug(con->drizzle, "drizzle_state_packet_read");
 
43
 
 
44
  if (con->buffer_size < 4)
 
45
  {
 
46
    drizzle_state_push(con, drizzle_state_read);
 
47
    return DRIZZLE_RETURN_OK;
 
48
  }
 
49
 
 
50
  con->packet_size= drizzle_get_byte3(con->buffer_ptr);
 
51
 
 
52
  if (con->packet_number != con->buffer_ptr[3])
 
53
  {
 
54
    drizzle_set_error(con->drizzle, "drizzle_state_packet_read",
 
55
                      "bad packet number:%u:%u", con->packet_number,
 
56
                      con->buffer_ptr[3]);
 
57
    return DRIZZLE_RETURN_BAD_PACKET_NUMBER;
 
58
  }
 
59
 
 
60
  drizzle_log_debug(con->drizzle, "packet_size= %zu, packet_number= %u",
 
61
                    con->packet_size, con->packet_number);
 
62
 
 
63
  con->packet_number++;
 
64
 
 
65
  con->buffer_ptr+= 4;
 
66
  con->buffer_size-= 4;
 
67
 
 
68
  drizzle_state_pop(con);
 
69
  return DRIZZLE_RETURN_OK;
 
70
}