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.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     1
/*
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     2
    Task Spooler - a task queue system for the unix user
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     3
    Copyright (C) 2007  LluĂ­s Batlle i Rossell
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     4
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     5
    Please find the license in the provided COPYING file.
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     6
*/
44
4dcf05746ece Better include files.
viric@llimona
parents: 32
diff changeset
     7
#include <sys/types.h>
4dcf05746ece Better include files.
viric@llimona
parents: 32
diff changeset
     8
#include <sys/socket.h>
4dcf05746ece Better include files.
viric@llimona
parents: 32
diff changeset
     9
#include <stdio.h>
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
    10
#include <sys/time.h>
44
4dcf05746ece Better include files.
viric@llimona
parents: 32
diff changeset
    11
#include <stdlib.h>
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 49
diff changeset
    12
#include "main.h"
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    13
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    14
void send_bytes(const int fd, const char *data, const int bytes)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    15
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    16
    int res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    17
    /* Send the message */
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    18
    res = send(fd, data, bytes, 0);
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    19
    if(res == -1)
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 49
diff changeset
    20
        warning("Sending %i bytes to %i.", bytes, fd);
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    21
}
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    22
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    23
int recv_bytes(const int fd, char *data, const int bytes)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    24
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    25
    int res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    26
    /* Send the message */
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    27
    res = recv(fd, data, bytes, 0);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 49
diff changeset
    28
    if(res == -1)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 49
diff changeset
    29
        warning("Receiving %i bytes from %i.", bytes, fd);
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    30
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    31
    return res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    32
}
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    33
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    34
void send_msg(const int fd, const struct msg *m)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    35
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    36
    int res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    37
    /* Send the message */
111
d6bc62904b5a Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents: 92
diff changeset
    38
    if (0)
d6bc62904b5a Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents: 92
diff changeset
    39
        msgdump(stderr, m);
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    40
    res = send(fd, m, sizeof(*m), 0);
111
d6bc62904b5a Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents: 92
diff changeset
    41
    if(res == -1 && 0)
d6bc62904b5a Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents: 92
diff changeset
    42
        warning_msg(m, "Sending a message to %i.", fd);
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    43
}
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    44
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    45
int recv_msg(const int fd, struct msg *m)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    46
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    47
    int res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    48
    /* Send the message */
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 19
diff changeset
    49
    res = recv(fd, m, sizeof(*m), 0);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 49
diff changeset
    50
    if(res == -1)
111
d6bc62904b5a Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents: 92
diff changeset
    51
        warning_msg(m, "Receiving a message from %i.", fd);
d6bc62904b5a Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents: 92
diff changeset
    52
    if (res == sizeof(*m) && 0)
d6bc62904b5a Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents: 92
diff changeset
    53
        msgdump(stderr, m);
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    54
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    55
    return res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    56
}