Skip to content

Commit

Permalink
clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebrady committed Jan 10, 2019
1 parent 1c40176 commit 8f20e58
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
8 changes: 4 additions & 4 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,16 +1160,16 @@ int sps_pthread_mutex_timedlock(pthread_mutex_t *mutex, useconds_t dally_time,

timeoutTime.tv_sec = time_then;
timeoutTime.tv_nsec = time_then_nsec;
int64_t start_time = get_absolute_time_in_fp();
int64_t start_time = get_absolute_time_in_fp();
int r = pthread_mutex_timedlock(mutex, &timeoutTime);
int64_t et = get_absolute_time_in_fp() - start_time;

if ((debuglevel != 0) && (r != 0) && (debugmessage != NULL)) {
et = (et * 1000000) >> 32; // microseconds
et = (et * 1000000) >> 32; // microseconds
char errstr[1000];
if (r == ETIMEDOUT)
debug(debuglevel,
"timed out waiting for a mutex, having waiting %f seconds, with a maximum waiting time of %d microseconds. \"%s\".",
debug(debuglevel, "timed out waiting for a mutex, having waiting %f seconds, with a maximum "
"waiting time of %d microseconds. \"%s\".",
(1.0 * et) / 1000000, dally_time, debugmessage);
else
debug(debuglevel, "error %d: \"%s\" waiting for a mutex: \"%s\".", r,
Expand Down
60 changes: 31 additions & 29 deletions dacp.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void addrinfo_cleanup(void *arg) {
void mutex_lock_cleanup(void *arg) {
pthread_mutex_t *m = (pthread_mutex_t *)arg;
if (pthread_mutex_unlock(m))
debug(1,"Error releasing mutex.");
debug(1, "Error releasing mutex.");
}

void connect_cleanup(void *arg) {
Expand Down Expand Up @@ -233,26 +233,25 @@ int dacp_send_command(const char *command, char **body, ssize_t *bodysize) {
command, dacp_server.ip_string, dacp_server.port, dacp_server.active_remote_id);

// Send command
debug(3,"dacp_send_command: \"%s\".",command);
debug(3, "dacp_send_command: \"%s\".", command);
ssize_t wresp = send(sockfd, message, strlen(message), 0);
if (wresp == -1) {
char errorstring[1024];
strerror_r(errno, (char *)errorstring, sizeof(errorstring));
debug(2, "dacp_send_command: write error %d: \"%s\".", errno, (char *)errorstring);
struct linger so_linger;
so_linger.l_onoff = 1; // "true"
so_linger.l_linger = 0;
int err = setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &so_linger, sizeof so_linger);
if (err)
debug(1, "Could not set the dacp socket to abort due to a write error on closing.");
}
char errorstring[1024];
strerror_r(errno, (char *)errorstring, sizeof(errorstring));
debug(2, "dacp_send_command: write error %d: \"%s\".", errno, (char *)errorstring);
struct linger so_linger;
so_linger.l_onoff = 1; // "true"
so_linger.l_linger = 0;
int err = setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &so_linger, sizeof so_linger);
if (err)
debug(1, "Could not set the dacp socket to abort due to a write error on closing.");
}
if (wresp != (ssize_t)strlen(message)) {
// debug(1, "dacp_send_command: send failed.");
response.code = 493; // Client failed to send a message

} else {


response.body = malloc(2048); // it can resize this if necessary
response.malloced_size = 2048;
pthread_cleanup_push(malloc_cleanup, response.body);
Expand All @@ -272,18 +271,20 @@ int dacp_send_command(const char *command, char **body, ssize_t *bodysize) {
ssize_t ndata = recv(sockfd, buffer, sizeof(buffer), 0);
// debug(3, "Received %d bytes: \"%s\".", ndata, buffer);
if (ndata <= 0) {
if (ndata == -1) {
char errorstring[1024];
strerror_r(errno, (char *)errorstring, sizeof(errorstring));
debug(2, "dacp_send_command: receiving error %d: \"%s\".", errno,(char *)errorstring);
struct linger so_linger;
so_linger.l_onoff = 1; // "true"
so_linger.l_linger = 0;
int err = setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &so_linger, sizeof so_linger);
if (err)
debug(1, "Could not set the dacp socket to abort due to a read error on closing.");
}

if (ndata == -1) {
char errorstring[1024];
strerror_r(errno, (char *)errorstring, sizeof(errorstring));
debug(2, "dacp_send_command: receiving error %d: \"%s\".", errno,
(char *)errorstring);
struct linger so_linger;
so_linger.l_onoff = 1; // "true"
so_linger.l_linger = 0;
int err = setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &so_linger, sizeof so_linger);
if (err)
debug(1,
"Could not set the dacp socket to abort due to a read error on closing.");
}

free(response.body);
response.body = NULL;
response.malloced_size = 0;
Expand Down Expand Up @@ -331,9 +332,10 @@ int dacp_send_command(const char *command, char **body, ssize_t *bodysize) {
}
pthread_cleanup_pop(1); // this should free the addrinfo
// freeaddrinfo(res);
uint64_t et = get_absolute_time_in_fp() - start_time;
et = (et * 1000000) >> 32; // microseconds
debug(2,"dacp_send_command: %f seconds, response code %d, command \"%s\".",(1.0 * et) / 1000000, response.code, command);
uint64_t et = get_absolute_time_in_fp() - start_time;
et = (et * 1000000) >> 32; // microseconds
debug(2, "dacp_send_command: %f seconds, response code %d, command \"%s\".",
(1.0 * et) / 1000000, response.code, command);
}
*body = response.body;
*bodysize = response.size;
Expand Down Expand Up @@ -856,7 +858,7 @@ void dacp_monitor_start() {
if (rc)
debug(1, "Error creating the DACP Conversation Lock Mutex Init");
else
debug(1, "DACP Conversation Lock Mutex Init");
debug(1, "DACP Conversation Lock Mutex Init");

rc = pthread_mutexattr_destroy(&mta);
if (rc)
Expand Down

0 comments on commit 8f20e58

Please sign in to comment.