msg.c
author viric@llimona
Tue, 27 Mar 2007 23:29:56 +0200
changeset 58 3c492266923e
parent 49 09bb8a5583e9
child 92 05004c52ecff
permissions -rw-r--r--
Preparing v0.2.3
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>
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    11
#include "msg.h"
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)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    19
    {
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    20
        perror("c: send");
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    21
        exit(-1);
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
}
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 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
    26
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    27
    int res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    28
    /* Send the message */
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    29
    res = recv(fd, data, bytes, 0);
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 */
32
3531439f2770 Tail works.
viric@llimona
parents: 21
diff changeset
    38
    msgdump(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);
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    40
    if(res == -1)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    41
    {
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    42
        perror("c: send");
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    43
        exit(-1);
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
}
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 recv_msg(const int fd, struct msg *m)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    48
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    49
    int res;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff changeset
    50
    /* Send the message */
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 19
diff changeset
    51
    res = recv(fd, m, sizeof(*m), 0);
32
3531439f2770 Tail works.
viric@llimona
parents: 21
diff changeset
    52
    if (res == sizeof(*m))
3531439f2770 Tail works.
viric@llimona
parents: 21
diff changeset
    53
        msgdump(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
}