msg.c
author viric@llimona
Mon, 12 Nov 2007 09:57:46 +0100
changeset 140 0b99d94818d1
parent 117 db479ef293d3
child 146 5e689cb593aa
permissions -rw-r--r--
Added the web page.
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>
4dcf05746ece Better include files.
viric@llimona
parents: 32
diff changeset
    10
#include <stdlib.h>
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 49
diff changeset
    11
#include "main.h"
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    12
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    13
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
    14
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    15
    int res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    16
    /* Send the message */
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    17
    res = send(fd, data, bytes, 0);
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    18
    if(res == -1)
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 49
diff changeset
    19
        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
    20
}
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
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
    23
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    24
    int res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    25
    /* Send the message */
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    26
    res = recv(fd, data, bytes, 0);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 49
diff changeset
    27
    if(res == -1)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 49
diff changeset
    28
        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
    29
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    30
    return res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    31
}
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
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
    34
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    35
    int res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    36
    /* Send the message */
111
d6bc62904b5a Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents: 92
diff changeset
    37
    if (0)
d6bc62904b5a Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents: 92
diff changeset
    38
        msgdump(stderr, m);
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    39
    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
    40
    if(res == -1 && 0)
d6bc62904b5a Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents: 92
diff changeset
    41
        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
    42
}
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
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
    45
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    46
    int res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    47
    /* Send the message */
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 19
diff changeset
    48
    res = recv(fd, m, sizeof(*m), 0);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 49
diff changeset
    49
    if(res == -1)
111
d6bc62904b5a Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents: 92
diff changeset
    50
        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
    51
    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
    52
        msgdump(stderr, m);
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    53
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    54
    return res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    55
}