Drizzled Public API Documentation

state.c

Go to the documentation of this file.
00001 /*
00002  * Drizzle Client & Protocol Library
00003  *
00004  * Copyright (C) 2008 Eric Day (eday@oddments.org)
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are
00009  * met:
00010  *
00011  *     * Redistributions of source code must retain the above copyright
00012  * notice, this list of conditions and the following disclaimer.
00013  *
00014  *     * Redistributions in binary form must reproduce the above
00015  * copyright notice, this list of conditions and the following disclaimer
00016  * in the documentation and/or other materials provided with the
00017  * distribution.
00018  *
00019  *     * The names of its contributors may not be used to endorse or
00020  * promote products derived from this software without specific prior
00021  * written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  */
00036 
00042 #include "common.h"
00043 
00044 drizzle_return_t drizzle_state_loop(drizzle_con_st *con)
00045 {
00046   drizzle_return_t ret;
00047 
00048   while (!drizzle_state_none(con))
00049   {
00050     ret= con->state_stack[con->state_current - 1](con);
00051     if (ret != DRIZZLE_RETURN_OK)
00052     {
00053       if (ret != DRIZZLE_RETURN_IO_WAIT && ret != DRIZZLE_RETURN_PAUSE &&
00054           ret != DRIZZLE_RETURN_ERROR_CODE)
00055       {
00056         drizzle_con_close(con);
00057       }
00058 
00059       return ret;
00060     }
00061   }
00062 
00063   return DRIZZLE_RETURN_OK;
00064 }
00065 
00066 drizzle_return_t drizzle_state_packet_read(drizzle_con_st *con)
00067 {
00068   drizzle_log_debug(con->drizzle, "drizzle_state_packet_read");
00069 
00070   if (con->buffer_size < 4)
00071   {
00072     drizzle_state_push(con, drizzle_state_read);
00073     return DRIZZLE_RETURN_OK;
00074   }
00075 
00076   con->packet_size= drizzle_get_byte3(con->buffer_ptr);
00077 
00078   if (con->packet_number != con->buffer_ptr[3])
00079   {
00080     drizzle_set_error(con->drizzle, "drizzle_state_packet_read",
00081                       "bad packet number:%u:%u", con->packet_number,
00082                       con->buffer_ptr[3]);
00083     return DRIZZLE_RETURN_BAD_PACKET_NUMBER;
00084   }
00085 
00086   drizzle_log_debug(con->drizzle, "packet_size= %zu, packet_number= %u",
00087                     con->packet_size, con->packet_number);
00088 
00089   con->packet_number++;
00090 
00091   con->buffer_ptr+= 4;
00092   con->buffer_size-= 4;
00093 
00094   drizzle_state_pop(con);
00095   return DRIZZLE_RETURN_OK;
00096 }