capmt_send_msg(capmt_t *capmt, int sid, const uint8_t *buf, size_t len)
{
if (capmt->capmt_oscam) {
- int i, sent = 0;
+ int i;
// dumping current SID table
for (i = 0; i < MAX_SOCKETS; i++)
tvhlog(LOG_DEBUG, "capmt", "created socket with socket_fd=%d", capmt->capmt_sock[i]);
}
if (capmt->capmt_sock[i] > 0) {
- sent = write(capmt->capmt_sock[i], buf, len);
- tvhlog(LOG_DEBUG, "capmt", "socket_fd=%d len=%d sent=%d", capmt->capmt_sock[i], (int)len, sent);
- if (sent != len) {
- tvhlog(LOG_ERR, "capmt", "%s: len != sent", __FUNCTION__);
+ if (tvh_write(capmt->capmt_sock[i], buf, len)) {
+ tvhlog(LOG_DEBUG, "capmt", "socket_fd=%d send failed", capmt->capmt_sock[i]);
close(capmt->capmt_sock[i]);
capmt->capmt_sock[i] = 0;
+ return -1;
}
}
- return sent;
}
else // standard old capmt mode
- return write(capmt->capmt_sock[0], buf, len);
+ tvh_write(capmt->capmt_sock[0], buf, len);
+ return 0;
}
static void
{
cwc_message_t *cm = malloc(sizeof(cwc_message_t));
uint8_t *buf = cm->cm_data;
- int seq, n;
+ int seq;
if(len + 12 > CWS_NETMSGSIZE) {
free(cm);
pthread_cond_signal(&cwc->cwc_writer_cond);
pthread_mutex_unlock(&cwc->cwc_writer_mutex);
} else {
- n = write(cwc->cwc_fd, buf, len);
- if(n != len)
+ if (tvh_write(cwc->cwc_fd, buf, len))
tvhlog(LOG_INFO, "cwc", "write error %s", strerror(errno));
free(cm);
TAILQ_REMOVE(&cwc->cwc_writeq, cm, cm_link);
pthread_mutex_unlock(&cwc->cwc_writer_mutex);
// int64_t ts = getmonoclock();
- r = write(cwc->cwc_fd, cm->cm_data, cm->cm_len);
+ if (tvh_write(cwc->cwc_fd, cm->cm_data, cm->cm_len))
+ tvhlog(LOG_INFO, "cwc", "write error %s", strerror(errno));
// printf("Write took %lld usec\n", getmonoclock() - ts);
free(cm);
pthread_mutex_lock(&cwc->cwc_writer_mutex);
/* Stop DVR thread */
if (tda->tda_dvr_pipe.rd != -1) {
tvhlog(LOG_DEBUG, "dvb", "%s stopping thread", tda->tda_rootpath);
- int err = write(tda->tda_dvr_pipe.wr, "", 1);
- assert(err != -1);
+ int err = tvh_write(tda->tda_dvr_pipe.wr, "", 1);
+ assert(!err);
pthread_join(tda->tda_dvr_thread, NULL);
close(tda->tda_dvr_pipe.rd);
close(tda->tda_dvr_pipe.wr);
int r = htsmsg_binary_serialize(m, &msgdata, &msglen, 0x10000);
htsmsg_destroy(m);
if (!r) {
- ssize_t w = write(fd, msgdata, msglen);
+ ret = tvh_write(fd, msgdata, msglen);
free(msgdata);
- if(w == msglen) ret = 0;
}
} else {
ret = 0;
htsp_write_scheduler(void *aux)
{
htsp_connection_t *htsp = aux;
- int r;
htsp_msg_q_t *hmq;
htsp_msg_t *hm;
void *dptr;
pthread_mutex_unlock(&htsp->htsp_out_mutex);
- r = htsmsg_binary_serialize(hm->hm_msg, &dptr, &dlen, INT32_MAX);
+ if (htsmsg_binary_serialize(hm->hm_msg, &dptr, &dlen, INT32_MAX) != 0) {
+ tvhlog(LOG_WARNING, "htsp", "%s: failed to serialize data",
+ htsp->htsp_logname);
+ }
htsp_msg_destroy(hm);
- void *freeme = dptr;
-
- while(dlen > 0) {
- r = write(htsp->htsp_fd, dptr, dlen);
- if(r < 0) {
- if(errno == EAGAIN || errno == EWOULDBLOCK)
- continue;
- tvhlog(LOG_INFO, "htsp", "%s: Write error -- %s",
- htsp->htsp_logname, strerror(errno));
- break;
- }
- if(r == 0) {
- tvhlog(LOG_ERR, "htsp", "%s: write() returned 0",
- htsp->htsp_logname);
- }
- dptr += r;
- dlen -= r;
+ if (tvh_write(htsp->htsp_fd, dptr, dlen)) {
+ tvhlog(LOG_INFO, "htsp", "%s: Write error -- %s",
+ htsp->htsp_logname, strerror(errno));
+ break;
}
- free(freeme);
+ free(dptr);
pthread_mutex_lock(&htsp->htsp_out_mutex);
- if(dlen)
- break;
}
// Shutdown socket to make receive thread terminate entire HTSP connection
htsbuf_queue_init(&hq, 0);
htsmsg_json_serialize(record, &hq, 1);
TAILQ_FOREACH(hd, &hq.hq_q, hd_link)
- if(write(fd, hd->hd_data + hd->hd_data_off, hd->hd_data_len) !=
- hd->hd_data_len) {
+ if(tvh_write(fd, hd->hd_data + hd->hd_data_off, hd->hd_data_len)) {
tvhlog(LOG_ALERT, "settings", "Failed to write file \"%s\" - %s",
tmppath, strerror(errno));
ok = 0;
assert(va->va_current_service != NULL);
- if(write(va->va_pipe[1], &c, 1) != 1)
+ if(tvh_write(va->va_pipe[1], &c, 1))
tvhlog(LOG_ERR, "v4l", "Unable to close video thread -- %s",
strerror(errno));