chiark / gitweb /
Quieten compiler.
[disorder] / lib / speaker-protocol.c
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
ea410ba1 3 * Copyright (C) 2005, 2007 Richard Kettlewell
460b9539 4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
460b9539 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
460b9539 8 * (at your option) any later version.
e7eb3a27
RK
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
460b9539 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
460b9539 17 */
ea410ba1 18/** @file lib/speaker-protocol.c
19 * @brief Speaker/server protocol support
20 */
460b9539 21
05b75f8d 22#include "common.h"
460b9539 23
24#include <sys/socket.h>
460b9539 25#include <errno.h>
84aa9f93
RK
26#include <unistd.h>
27#include <stddef.h>
460b9539 28
ea410ba1 29#include "speaker-protocol.h"
460b9539 30#include "log.h"
31
fbf86993 32/** @brief Send a speaker message
ea410ba1 33 * @param fd File descriptor to send to
34 * @param sm Pointer to message
ea410ba1 35 */
84aa9f93 36void speaker_send(int fd, const struct speaker_message *sm) {
460b9539 37 int ret;
38
460b9539 39 do {
84aa9f93 40 ret = write(fd, sm, sizeof *sm);
460b9539 41 } while(ret < 0 && errno == EINTR);
42 if(ret < 0)
84aa9f93 43 fatal(errno, "write");
460b9539 44}
45
ea410ba1 46/** @brief Receive a speaker message
47 * @param fd File descriptor to read from
48 * @param sm Where to store received message
ea410ba1 49 * @return -ve on @c EAGAIN, 0 at EOF, +ve on success
ea410ba1 50 */
84aa9f93 51int speaker_recv(int fd, struct speaker_message *sm) {
460b9539 52 int ret;
53
460b9539 54 do {
84aa9f93 55 ret = read(fd, sm, sizeof *sm);
460b9539 56 } while(ret < 0 && errno == EINTR);
57 if(ret < 0) {
58 if(errno != EAGAIN) fatal(errno, "recvmsg");
59 return -1;
60 }
460b9539 61 return ret;
62}
63
64/*
65Local Variables:
66c-basic-offset:2
67comment-column:40
68fill-column:79
69indent-tabs-mode:nil
70End:
71*/