msg.c
author viric@llimona
Sat, 09 Feb 2008 11:56:03 +0100
changeset 196 bca29e2a1a86
parent 146 5e689cb593aa
child 231 558b281b88f5
permissions -rw-r--r--
Fixing a bug related to a message on -t on last job, when it was skipped.

/*
    Task Spooler - a task queue system for the unix user
    Copyright (C) 2007  LluĂ­s Batlle i Rossell

    Please find the license in the provided COPYING file.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>
#include "main.h"

void send_bytes(const int fd, const char *data, const int bytes)
{
    int res;
    /* Send the message */
    res = send(fd, data, bytes, 0);
    if(res == -1)
        warning("Sending %i bytes to %i.", bytes, fd);
}

int recv_bytes(const int fd, char *data, const int bytes)
{
    int res;
    /* Send the message */
    res = recv(fd, data, bytes, 0);
    if(res == -1)
        warning("Receiving %i bytes from %i.", bytes, fd);

    return res;
}

void send_msg(const int fd, const struct msg *m)
{
    int res;
    /* Send the message */
    if (0)
        msgdump(stderr, m);
    res = send(fd, m, sizeof(*m), 0);
    if(res == -1 && 0)
        warning_msg(m, "Sending a message to %i.", fd);
}

int recv_msg(const int fd, struct msg *m)
{
    int res;
    /* Send the message */
    res = recv(fd, m, sizeof(*m), 0);
    if(res == -1)
        warning_msg(m, "Receiving a message from %i.", fd);
    if (res == sizeof(*m) && 0)
        msgdump(stderr, m);

    return res;
}