Ejemplo n.º 1
0
static __inline__ gint
__hm_watch_write_message(HmWatch *watch, gpointer msg)
{
    gchar packet[MAX_IO_BUFFER_SIZE];
    gint ret = 0, pending = 0;
    HmWatchFuncs *funcs;

    funcs = watch->funcs;
    BUG_ON(!funcs);

    if (funcs->format)      /* if !funcs->format, return 0 */
    {
        ret = (*funcs->format)(watch, msg, packet,
            MAX_IO_BUFFER_SIZE);
        if (ret > 0)
        {
            ret = hm_net_buf_write(watch->buffer, packet, ret, 
                watch, &pending);
            if (!ret)
            {
#ifdef __HANDLE_SENDING_FAIL_EVENT
              hm_print(
                  "Net watch '%p' snd buffer full, drop 1 packet.",
                  watch
              );

              g_source_destroy((GSource*)watch);
              __hm_watch_error(watch, 1, -E_SNDBUFFULL);
#endif
            }
            else if (ret < 0)
            {
                hm_print(
                    "Net IO '%p' send failed.", NET_IO(watch)
                );

                g_source_destroy((GSource*)watch);
                __hm_watch_error(watch, 1, ret);
            }
            else
            {
                if (pending && !watch->w_pending)
                {
                    watch->w_fd.revents = 0;
                    g_source_add_poll((GSource*)watch, &watch->w_fd);
                    watch->w_pending = 1;
                }
            }
        }
        else
        {
            hm_print(
                "Net format packet failed while sending, drop."
            );
        }
    }

    return ret;
}
Ejemplo n.º 2
0
rt_inline void temp_print_epd(struct hm_temp_data* data)
{
#define   HOT    (0)
#define   COLD   (1)
    static struct hm_print_data pd[2];
    static char buf[2][10];
    sprintf(buf[HOT], "%2.1f", data->hot);
    pd[HOT].x = 36;
    pd[HOT].y = 2;
    pd[HOT].str = buf[HOT];
    hm_print(&pd[HOT]);
    sprintf(buf[COLD], "%2.1f", data->cold);
    pd[COLD].x = 115;
    pd[COLD].y = 2;
    pd[COLD].str = buf[COLD];
    hm_print(&pd[COLD]);
}
Ejemplo n.º 3
0
static void
hm_hl_io_on_close(HmIO *io, gint async)
{
	hm_print(
		"Net IO '%p' closed%s, report from hl layer.",
		NET_IO(io), async ? " by peer" : ""
	);
}
Ejemplo n.º 4
0
void debug_print() {
    printf("%s, version %s\n", PROGRAM_NAME, PROGRAM_VERSION);
    printf("   compiled %s, %s\n\n", __DATE__, __TIME__);
    printf("Entering debug mode (non daemon)...\n\n");
    printf("%s:\n", SETTINGS_FILE);
    hm_print(settings, stdout, to_string);
    printf("\nSleep timeout = %d ms\n", sleep_timeout);
    printf("\nStarting poll...\n");
}
Ejemplo n.º 5
0
rt_inline void tof_print_epd(float data)
{
    static struct hm_print_data pd;
    static char buf[10];
    sprintf(buf, "%2.3f", data);
    pd.x = 36;
    pd.y = 12;
    pd.str = buf;
    hm_print(&pd);
}
Ejemplo n.º 6
0
rt_inline void heat_print(float heat)
{
    static struct hm_print_data pd;
    static char buf[10];
    sprintf(buf, "%.2f", heat);
    pd.x = 36;
    pd.y = 7;
    pd.str = buf;
    hm_print(&pd);
}
Ejemplo n.º 7
0
static gboolean
hm_watch_rw_dispatch(HmWatch *watch, gpointer user_data)
{
    HmWatchFuncs *funcs;
    gint err = 0, timeout = 1;
    socklen_t len = sizeof(err);
    gchar buf[MAX_IO_BUFFER_SIZE];

    funcs = watch->funcs;
    BUG_ON(!funcs);

    if (watch->r_fd.revents & READ_COND)
    {
        timeout = 0;

        if (watch->r_fd.revents & READ_ERR)
        {
            getsockopt(watch->r_fd.fd, SOL_SOCKET, SO_ERROR, &err, &len);
            err = -err;
            goto read_error;
        }

        for (;;)
        {
            if (watch->killed)
                return FALSE;   /* end the loop if killed, funcs->recv() may drop lock. */

            err = hm_connection_read(watch->conn, buf, MAX_IO_BUFFER_SIZE);
            if (err == 0)
            {
                goto conn_reset;
            }
            else if (err > 0)
            {
                if (funcs->recv)
                {
                    if ((err = (*funcs->recv)(watch, buf, err)))
                    {
                        goto read_error;
                    }
                }
                else
                {
                    watch->r_fd.revents = 0;    /* no reader */
                    g_source_remove_poll((GSource*)watch, &watch->r_fd);
                    break;  /* data will stay in the sock buffer */
                }
            }
            else
            {
                if (err == -EAGAIN)
                    break;

                goto read_error;
            }
        }
    }

    if (watch->w_fd.revents & WRITE_COND)
    {
        timeout = 0;

        if (G_UNLIKELY(hm_connection_is_ingrogress(watch->conn, 1)))
        {
            if (getsockopt(watch->w_fd.fd, SOL_SOCKET, SO_ERROR, &err, &len))
            {
                hm_warning("getsockopt() after connect() failed");
                err = -errno;
                goto write_error;
            }

            if (err)
            {
                err = -err;
                goto write_error;
            }

            watch->w_fd.revents = 0;
            g_source_remove_poll((GSource*)watch, &watch->w_fd);
            g_source_add_poll((GSource*)watch, &watch->r_fd);

            g_mutex_unlock(watch->lock);    /* drop the lock*/
            hm_watch_on_establish(watch);
            g_mutex_lock(watch->lock);          
        }
        else
        {
            if (watch->w_fd.revents & WRITE_ERR)
            {
                len = sizeof(err);
                getsockopt(watch->w_fd.fd, SOL_SOCKET, SO_ERROR, &err, &len);
                err = -err;
                goto write_error;
            }
    
            err = hm_net_buf_flush(watch->buffer, watch);
            if (!err)   /* all data flushed */
            {
                watch->w_fd.revents = 0;
                g_source_remove_poll((GSource*)watch, &watch->w_fd);
                watch->w_pending = 0;
            }
            else
            {
                if (err < 0)
                    goto write_error;
            }
        }
    }

    if (timeout)
    {
        hm_print(
            "Net IO '%p' timeout.", NET_IO(watch)
        );
        __hm_watch_error(watch, 0, -E_CONNTIMEOUT);
        return FALSE;
    }

    return TRUE;

conn_reset:
    __hm_watch_close(watch, 1);
    return FALSE;

read_error:
    __hm_watch_error(watch, 0, err);
    return FALSE;

write_error:
    __hm_watch_error(watch, 1, err);
    return FALSE;       
}
Ejemplo n.º 8
0
static __inline__ void
hm_debug_on_exit(gint status, gpointer arg)
{
    hm_print("<EXIT> SERVER EXITED.");
}