<commit_before>/*
 * Copyright (c) 2004-2006 <NAME> <<EMAIL>>
 * Copyright (c) 2006-2014 Sippy Software, Inc., http://www.sippysoft.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id$
 *
 */

#include <assert.h>
#include <poll.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>


#include "rtp.h"
#include "rtp_resizer.h"
#include "rtp_server.h"
#include "rtpp_log.h"
#include "rtpp_network.h"
#include "rtpp_notify.h"
#include "rtpp_bulk_netio.h"
#include "rtpp_proc.h"
#include "rtpp_record.h"
#include "rtpp_session.h"
#include "rtpp_util.h"

struct rtpp_proc_out_lst {
    struct rtpp_session *sp;
    int ridx;
    struct rtp_packet *packet;
};

struct rtpp_proc_ready_lst {
    struct rtpp_session *sp;
    int ridx;
};

static void send_packets(struct cfg *, struct rtpp_proc_out_lst *, int, \
  struct rtpp_bnet_opipe *);

void
process_rtp_servers(struct cfg *cf, double dtime, struct rtpp_bnet_opipe *op)
{
    int j, sidx, len, skipfd;
    struct rtpp_session *sp;
    struct rtp_packet *pkt;

    skipfd = 0;
    for (j = 0; j < cf->rtp_nsessions; j++) {
	sp = cf->rtp_servers[j];
	if (sp == NULL) {
	    skipfd++;
	    continue;
	}
	if (skipfd > 0) {
	    cf->rtp_servers[j - skipfd] = cf->rtp_servers[j];
	    sp->sridx = j - skipfd;
	}
	for (sidx = 0; sidx < 2; sidx++) {
	    if (sp->rtps[sidx] == NULL || sp->addr[sidx] == NULL)
		continue;
            for (;;) {
                pkt = rtp_server_get(sp->rtps[sidx], dtime, &len);
                if (pkt == NULL) {
                    if (len == RTPS_EOF) {
                        rtp_server_free(sp->rtps[sidx]);
                        sp->rtps[sidx] = NULL;
                        if (sp->rtps[0] == NULL && sp->rtps[1] == NULL) {
                            assert(cf->rtp_servers[sp->sridx] == sp);
                            cf->rtp_servers[sp->sridx] = NULL;
                            sp->sridx = -1;
                        }
                    } else if (len != RTPS_LATER) {
                        /* XXX some error, brag to logs */<commit_msg>Call rtpp_bulk_netio_opipe_flush before we deallocate server.<commit_after>/*
 * Copyright (c) 2004-2006 <NAME> <<EMAIL>>
 * Copyright (c) 2006-2014 Sippy Software, Inc., http://www.sippysoft.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id$
 *
 */

#include <assert.h>
#include <poll.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>


#include "rtp.h"
#include "rtp_resizer.h"
#include "rtp_server.h"
#include "rtpp_log.h"
#include "rtpp_network.h"
#include "rtpp_notify.h"
#include "rtpp_bulk_netio.h"
#include "rtpp_proc.h"
#include "rtpp_record.h"
#include "rtpp_session.h"
#include "rtpp_util.h"

struct rtpp_proc_out_lst {
    struct rtpp_session *sp;
    int ridx;
    struct rtp_packet *packet;
};

struct rtpp_proc_ready_lst {
    struct rtpp_session *sp;
    int ridx;
};

static void send_packets(struct cfg *, struct rtpp_proc_out_lst *, int, \
  struct rtpp_bnet_opipe *);

void
process_rtp_servers(struct cfg *cf, double dtime, struct rtpp_bnet_opipe *op)
{
    int j, sidx, len, skipfd;
    struct rtpp_session *sp;
    struct rtp_packet *pkt;

    skipfd = 0;
    for (j = 0; j < cf->rtp_nsessions; j++) {
	sp = cf->rtp_servers[j];
	if (sp == NULL) {
	    skipfd++;
	    continue;
	}
	if (skipfd > 0) {
	    cf->rtp_servers[j - skipfd] = cf->rtp_servers[j];
	    sp->sridx = j - skipfd;
	}
	for (sidx = 0; sidx < 2; sidx++) {
	    if (sp->rtps[sidx] == NULL || sp->addr[sidx] == NULL)
		continue;
            for (;;) {
                pkt = rtp_server_get(sp->rtps[sidx], dtime, &len);
                if (pkt == NULL) {
                    if (len == RTPS_EOF) {
                        rtpp_bulk_netio_opipe_flush(op);
                        rtp_server_free(sp->rtps[sidx]);
                        sp->rtps[sidx] = NULL;
                        if (sp->rtps[0] == NULL && sp->rtps[1] == NULL) {
                            assert(cf->rtp_servers[sp->sridx] == sp);
                            cf->rtp_servers[sp->sridx] = NULL;
                            sp->sridx = -1;
                        }
                    } else if (len != RTPS_LATER) {
                        /* XXX some error, brag to logs */
{'fraction_non_alphanumeric': 0.11209013433482594, 'fraction_numerical': 0.007511194568828542, 'mean_word_length': 2.7467532467532467, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7406598', 'n_tokens_mistral': 2379, 'n_tokens_neox': 2208, 'n_words': 720}