Compare commits
15 commits
feature/di
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
69bfc62890 | ||
|
022e3419d8 | ||
|
6ef2a74206 | ||
|
17b8c7b3c0 | ||
|
055127ca31 | ||
|
eabc2c50dc | ||
|
f5ef7b0c70 | ||
|
f565d2a4bf | ||
|
07236afacd | ||
|
d76ea6378e | ||
|
d8a7723051 | ||
|
d1c5628f50 | ||
|
1baa45ab05 | ||
|
a0e796326c | ||
|
fbf4ffbd32 |
9 changed files with 117 additions and 40 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,6 +3,7 @@ nmux
|
||||||
ddcd
|
ddcd
|
||||||
*.o
|
*.o
|
||||||
*.so
|
*.so
|
||||||
|
*.so.*
|
||||||
tags
|
tags
|
||||||
dumpvect.*.vect
|
dumpvect.*.vect
|
||||||
*.swp
|
*.swp
|
||||||
|
|
31
Makefile
31
Makefile
|
@ -28,13 +28,7 @@
|
||||||
|
|
||||||
LIBSOURCES = fft_fftw.c libcsdr_wrapper.c
|
LIBSOURCES = fft_fftw.c libcsdr_wrapper.c
|
||||||
#SOURCES = csdr.c $(LIBSOURCES)
|
#SOURCES = csdr.c $(LIBSOURCES)
|
||||||
cpufeature = $(if $(findstring $(1),$(shell cat /proc/cpuinfo)),$(2))
|
PARAMS_SIMD = $(shell ./detect_params.sh)
|
||||||
PARAMS_SSE = $(call cpufeature,sse,-msse) $(call cpufeature,sse2,-msse2) $(call cpufeature,sse3,-msse3) $(call cpufeature,sse4a,-msse4a) $(call cpufeature,sse4_1,-msse4.1) $(call cpufeature,sse4_2,-msse4.2 -msse4) -mfpmath=sse
|
|
||||||
PARAMS_NEON = -mfloat-abi=hard -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mvectorize-with-neon-quad -funsafe-math-optimizations -Wformat=0 -DNEON_OPTS
|
|
||||||
#tnx Jan Szumiec for the Raspberry Pi support
|
|
||||||
PARAMS_RASPI = -mfloat-abi=hard -mcpu=arm1176jzf-s -mfpu=vfp -funsafe-math-optimizations -Wformat=0
|
|
||||||
PARAMS_ARM = $(if $(call cpufeature,BCM2708,dummy-text),$(PARAMS_RASPI),$(PARAMS_NEON))
|
|
||||||
PARAMS_SIMD = $(if $(call cpufeature,sse,dummy-text),$(PARAMS_SSE),$(PARAMS_ARM))
|
|
||||||
PARAMS_LOOPVECT = -O3 -ffast-math -fdump-tree-vect-details -dumpbase dumpvect
|
PARAMS_LOOPVECT = -O3 -ffast-math -fdump-tree-vect-details -dumpbase dumpvect
|
||||||
PARAMS_LIBS = -g -lm -lrt -lfftw3f -DUSE_FFTW -DLIBCSDR_GPL -DUSE_IMA_ADPCM
|
PARAMS_LIBS = -g -lm -lrt -lfftw3f -DUSE_FFTW -DLIBCSDR_GPL -DUSE_IMA_ADPCM
|
||||||
PARAMS_SO = -fpic
|
PARAMS_SO = -fpic
|
||||||
|
@ -42,6 +36,8 @@ PARAMS_MISC = -Wno-unused-result
|
||||||
#DEBUG_ON = 0 #debug is always on by now (anyway it could be compiled with `make DEBUG_ON=1`)
|
#DEBUG_ON = 0 #debug is always on by now (anyway it could be compiled with `make DEBUG_ON=1`)
|
||||||
#PARAMS_DEBUG = $(if $(DEBUG_ON),-g,)
|
#PARAMS_DEBUG = $(if $(DEBUG_ON),-g,)
|
||||||
FFTW_PACKAGE = fftw-3.3.3
|
FFTW_PACKAGE = fftw-3.3.3
|
||||||
|
PREFIX ?= /usr
|
||||||
|
SOVERSION = 0.15
|
||||||
PARSEVECT ?= yes
|
PARSEVECT ?= yes
|
||||||
|
|
||||||
.PHONY: clean-vect clean codequality checkdocs v
|
.PHONY: clean-vect clean codequality checkdocs v
|
||||||
|
@ -51,7 +47,8 @@ libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c fastd
|
||||||
@echo Auto-detected optimization parameters: $(PARAMS_SIMD)
|
@echo Auto-detected optimization parameters: $(PARAMS_SIMD)
|
||||||
@echo
|
@echo
|
||||||
rm -f dumpvect*.vect
|
rm -f dumpvect*.vect
|
||||||
gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) $(LIBSOURCES) $(PARAMS_LIBS) $(PARAMS_MISC) -fpic -shared -o libcsdr.so
|
gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) $(LIBSOURCES) $(PARAMS_LIBS) $(PARAMS_MISC) -fpic -shared -Wl,-soname,libcsdr.so.$(SOVERSION) -o libcsdr.so.$(SOVERSION)
|
||||||
|
@ln -fs libcsdr.so.$(SOVERSION) libcsdr.so
|
||||||
ifeq ($(PARSEVECT),yes)
|
ifeq ($(PARSEVECT),yes)
|
||||||
-./parsevect dumpvect*.vect
|
-./parsevect dumpvect*.vect
|
||||||
endif
|
endif
|
||||||
|
@ -67,19 +64,19 @@ arm-cross: clean-vect
|
||||||
clean-vect:
|
clean-vect:
|
||||||
rm -f dumpvect*.vect
|
rm -f dumpvect*.vect
|
||||||
clean: clean-vect
|
clean: clean-vect
|
||||||
rm -f libcsdr.so csdr ddcd nmux
|
rm -f libcsdr.so.$(SOVERSION) csdr ddcd nmux *.o *.so
|
||||||
install: all
|
install: all
|
||||||
install -m 0755 libcsdr.so /usr/lib
|
install -m 0755 libcsdr.so.$(SOVERSION) $(PREFIX)/lib
|
||||||
install -m 0755 csdr /usr/bin
|
install -m 0755 csdr $(PREFIX)/bin
|
||||||
install -m 0755 csdr-fm /usr/bin
|
install -m 0755 csdr-fm $(PREFIX)/bin
|
||||||
install -m 0755 nmux /usr/bin
|
install -m 0755 nmux $(PREFIX)/bin
|
||||||
#-install -m 0755 ddcd /usr/bin
|
#-install -m 0755 ddcd $(PREFIX)/bin
|
||||||
ldconfig
|
@ldconfig || echo please run ldconfig
|
||||||
uninstall:
|
uninstall:
|
||||||
rm /usr/lib/libcsdr.so /usr/bin/csdr /usr/bin/csdr-fm
|
rm $(PREFIX)/lib/libcsdr.so.$(SOVERSION) $(PREFIX)/bin/csdr $(PREFIX)/bin/csdr-fm
|
||||||
ldconfig
|
ldconfig
|
||||||
disasm:
|
disasm:
|
||||||
objdump -S libcsdr.so > libcsdr.disasm
|
objdump -S libcsdr.so.$(SOVERSION) > libcsdr.disasm
|
||||||
emcc-clean:
|
emcc-clean:
|
||||||
-rm sdr.js/sdr.js
|
-rm sdr.js/sdr.js
|
||||||
-rm sdr.js/sdrjs-compiled.js
|
-rm sdr.js/sdrjs-compiled.js
|
||||||
|
|
|
@ -109,7 +109,7 @@ The first parameter is the frequency in MHz, and the second optional parameter i
|
||||||
|
|
||||||
rtl_sdr -s 2400000 -f 145000000 -g 20 - | csdr convert_u8_f | csdr shift_addition_cc `python -c "print float(145000000-144400000)/2400000"` | csdr fir_decimate_cc 50 0.005 HAMMING | csdr bandpass_fir_fft_cc 0 0.1 0.05 | csdr realpart_cf | csdr agc_ff | csdr limit_ff | csdr convert_f_s16 | mplayer -cache 1024 -quiet -rawaudio samplesize=2:channels=1:rate=48000 -demuxer rawaudio -
|
rtl_sdr -s 2400000 -f 145000000 -g 20 - | csdr convert_u8_f | csdr shift_addition_cc `python -c "print float(145000000-144400000)/2400000"` | csdr fir_decimate_cc 50 0.005 HAMMING | csdr bandpass_fir_fft_cc 0 0.1 0.05 | csdr realpart_cf | csdr agc_ff | csdr limit_ff | csdr convert_f_s16 | mplayer -cache 1024 -quiet -rawaudio samplesize=2:channels=1:rate=48000 -demuxer rawaudio -
|
||||||
|
|
||||||
- It is a modified Weaver-demodulator. The complex FIR filter removes the lower sideband and lets only the upper pass (USB). If you want to demodulate LSB, change `bandpass_fir_fft_cc 0 0.05` to `bandpass_fir_fft_cc -0.05 0`.
|
- It is a modified Weaver-demodulator. The complex FIR filter removes the lower sideband and lets only the upper pass (USB). If you want to demodulate LSB, change `bandpass_fir_fft_cc 0 0.1` to `bandpass_fir_fft_cc -0.1 0`.
|
||||||
|
|
||||||
### Draw FFT
|
### Draw FFT
|
||||||
|
|
||||||
|
@ -624,7 +624,7 @@ Syntax:
|
||||||
|
|
||||||
It is an automatic gain control function.
|
It is an automatic gain control function.
|
||||||
|
|
||||||
- `hang_time` is the number of samples to wait before strating to increase the gain after a peak.
|
- `hang_time` is the number of samples to wait before starting to increase the gain after a peak.
|
||||||
- `reference` is the reference level for the AGC. It tries to keep the amplitude of the output signal close to that.
|
- `reference` is the reference level for the AGC. It tries to keep the amplitude of the output signal close to that.
|
||||||
- `attack_rate` is the rate of decreasing the signal level if it gets higher than it used to be before.
|
- `attack_rate` is the rate of decreasing the signal level if it gets higher than it used to be before.
|
||||||
- `decay_rate` is the rate of increasing the signal level if it gets lower than it used to be before.
|
- `decay_rate` is the rate of increasing the signal level if it gets lower than it used to be before.
|
||||||
|
|
80
detect_params.sh
Executable file
80
detect_params.sh
Executable file
|
@ -0,0 +1,80 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# This software is part of libcsdr, a set of simple DSP routines for
|
||||||
|
# Software Defined Radio.
|
||||||
|
#
|
||||||
|
# Copyright (c) 2014, Andras Retzler <randras@sdr.hu>
|
||||||
|
# Copyright (c) 2019, MeFisto94
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions are met:
|
||||||
|
# * Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# * 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.
|
||||||
|
# * Neither the name of the copyright holder nor the
|
||||||
|
# names of its contributors may be used to endorse or promote products
|
||||||
|
# derived from this software without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 AUTHORS 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.
|
||||||
|
|
||||||
|
# This file will try to detect the correct GCC optimization parameters, especially when running on ARM Platforms such as the Raspberry Pi
|
||||||
|
|
||||||
|
# Desktop Processors
|
||||||
|
if grep -q sse /proc/cpuinfo; then
|
||||||
|
if grep -q sse /proc/cpuinfo; then
|
||||||
|
PARAMS_SSE="$PARAMS_SSE-msse"
|
||||||
|
fi
|
||||||
|
if grep -q sse2 /proc/cpuinfo; then
|
||||||
|
PARAMS_SSE="$PARAMS_SSE -msse2"
|
||||||
|
fi
|
||||||
|
if grep -q sse3 /proc/cpuinfo; then
|
||||||
|
PARAMS_SSE="$PARAMS_SSE -msse3"
|
||||||
|
fi
|
||||||
|
if grep -q sse4a /proc/cpuinfo; then
|
||||||
|
PARAMS_SSE="$PARAMS_SSE -msse4a"
|
||||||
|
fi
|
||||||
|
if grep -q sse4_1 /proc/cpuinfo; then
|
||||||
|
PARAMS_SSE="$PARAMS_SSE -msse4.1"
|
||||||
|
fi
|
||||||
|
# TODO: Is this "-msse4" only for sse4_2 intended?
|
||||||
|
if grep -q sse4_2 /proc/cpuinfo; then
|
||||||
|
PARAMS_SSE="$PARAMS_SSE -msse4.2 -msse4"
|
||||||
|
fi
|
||||||
|
echo "$PARAMS_SSE -mfpmath=sse"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
# Detect Raspberry Pi
|
||||||
|
if grep -q 'Raspberry' /proc/device-tree/model; then
|
||||||
|
if [ "$ARCH" = "aarch64" ]; then # Probably RPi 3+ on 64bit
|
||||||
|
# Float ABI is always hard on AARCH64. TODO: Does RPi 1 or 2 also have aarch64?
|
||||||
|
PARAMS_PI="-mcpu=cortex-a53 -mtune=cortex-a53"
|
||||||
|
else # note -mcpu replaces -march
|
||||||
|
# See https://gist.github.com/fm4dd/c663217935dc17f0fc73c9c81b0aa845
|
||||||
|
if grep -q 3 /proc/device-tree/model; then
|
||||||
|
PARAMS_PI="-mcpu=cortex-a53 -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits"
|
||||||
|
elif grep -q 2 /proc/device-tree/model; then
|
||||||
|
PARAMS_PI="-mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon-vfpv4"
|
||||||
|
elif grep -q 1 /proc/device-tree/model; then
|
||||||
|
PARAMS_PI="-mcpu=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
PARAMS_ARM="$PARAMS_PI -funsafe-math-optimizations -Wformat=0"
|
||||||
|
else # Generic ARM Device
|
||||||
|
# Most likely mtune is incorrect here
|
||||||
|
PARAMS_ARM = "-mfloat-abi=hard -march=`uname -m` -mtune=cortex-a8 -mfpu=neon -mvectorize-with-neon-quad -funsafe-math-optimizations -Wformat=0 -DNEON_OPTS"
|
||||||
|
fi
|
||||||
|
echo $PARAMS_ARM
|
||||||
|
return 0
|
||||||
|
fi
|
|
@ -1425,7 +1425,7 @@ psk31_varicode_item_t psk31_varicode_items[] =
|
||||||
{ .code = 0b101111011, .bitcount=9, .ascii=0x59 }, //Y
|
{ .code = 0b101111011, .bitcount=9, .ascii=0x59 }, //Y
|
||||||
{ .code = 0b1010101101, .bitcount=10, .ascii=0x5a }, //Z
|
{ .code = 0b1010101101, .bitcount=10, .ascii=0x5a }, //Z
|
||||||
{ .code = 0b111110111, .bitcount=9, .ascii=0x5b }, //[
|
{ .code = 0b111110111, .bitcount=9, .ascii=0x5b }, //[
|
||||||
{ .code = 0b111101111, .bitcount=9, .ascii=0x5c }, //\
|
{ .code = 0b111101111, .bitcount=9, .ascii=0x5c }, //backslash
|
||||||
{ .code = 0b111111011, .bitcount=9, .ascii=0x5d }, //]
|
{ .code = 0b111111011, .bitcount=9, .ascii=0x5d }, //]
|
||||||
{ .code = 0b1010111111, .bitcount=10, .ascii=0x5e }, //^
|
{ .code = 0b1010111111, .bitcount=10, .ascii=0x5e }, //^
|
||||||
{ .code = 0b101101101, .bitcount=9, .ascii=0x5f }, //_
|
{ .code = 0b101101101, .bitcount=9, .ascii=0x5f }, //_
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
Remove nmux repo, it will rather be part of csdr
|
|
||||||
Try in OpenWebRX
|
|
||||||
Add UDP support
|
|
||||||
Evaluate performance against ncat
|
|
||||||
Remove debug messages
|
|
||||||
Document README.md
|
|
||||||
Test with a limited number of people
|
|
28
nmux.cpp
28
nmux.cpp
|
@ -192,7 +192,7 @@ int main(int argc, char* argv[])
|
||||||
if(NMUX_DEBUG)
|
if(NMUX_DEBUG)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\x1b[1m\x1b[33mmainfor: clients before closing: ");
|
fprintf(stderr, "\x1b[1m\x1b[33mmainfor: clients before closing: ");
|
||||||
for(int i=0;i<clients.size();i++) fprintf(stderr, "0x%x ", (intptr_t)clients[i]);
|
for(int i=0;i<clients.size();i++) fprintf(stderr, "%p ", clients[i]);
|
||||||
fprintf(stderr, "\x1b[0m\n");
|
fprintf(stderr, "\x1b[0m\n");
|
||||||
}
|
}
|
||||||
if(NMUX_DEBUG) fprintf(stderr, "mainfor: accepted (socket = %d).\n", new_socket);
|
if(NMUX_DEBUG) fprintf(stderr, "mainfor: accepted (socket = %d).\n", new_socket);
|
||||||
|
@ -201,6 +201,12 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
if(clients[i]->status == CS_THREAD_FINISHED)
|
if(clients[i]->status == CS_THREAD_FINISHED)
|
||||||
{
|
{
|
||||||
|
if(pthread_detach(clients[i]->thread)!=0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"nmux pthread_detach failed for client %d\n", i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(NMUX_DEBUG) fprintf(stderr, "mainfor: client removed: %d\n", i);
|
if(NMUX_DEBUG) fprintf(stderr, "mainfor: client removed: %d\n", i);
|
||||||
//client destructor
|
//client destructor
|
||||||
pool->remove_thread(clients[i]->tsmthread);
|
pool->remove_thread(clients[i]->tsmthread);
|
||||||
|
@ -211,7 +217,7 @@ int main(int argc, char* argv[])
|
||||||
if(NMUX_DEBUG)
|
if(NMUX_DEBUG)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\x1b[1m\x1b[33mmainfor: clients after closing: ");
|
fprintf(stderr, "\x1b[1m\x1b[33mmainfor: clients after closing: ");
|
||||||
for(int i=0;i<clients.size();i++) fprintf(stderr, "0x%x ", (intptr_t)clients[i]);
|
for(int i=0;i<clients.size();i++) fprintf(stderr, "%p ", clients[i]);
|
||||||
fprintf(stderr, "\x1b[0m\n");
|
fprintf(stderr, "\x1b[0m\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +233,7 @@ int main(int argc, char* argv[])
|
||||||
if(pthread_create(&new_client->thread, NULL, client_thread, (void*)new_client)==0)
|
if(pthread_create(&new_client->thread, NULL, client_thread, (void*)new_client)==0)
|
||||||
{
|
{
|
||||||
clients.push_back(new_client);
|
clients.push_back(new_client);
|
||||||
fprintf(stderr, MSG_START "pthread_create() done, clients now: %d\n", clients.size());
|
fprintf(stderr, MSG_START "pthread_create() done, clients now: %d\n", (int)clients.size());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -278,14 +284,14 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
void* client_thread (void* param)
|
void* client_thread (void* param)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "client 0x%x: started!\n", (intptr_t)param);
|
fprintf(stderr, "client %p: started!\n", param);
|
||||||
client_t* this_client = (client_t*)param;
|
client_t* this_client = (client_t*)param;
|
||||||
this_client->status = CS_THREAD_RUNNING;
|
this_client->status = CS_THREAD_RUNNING;
|
||||||
int retval;
|
int retval;
|
||||||
tsmpool* lpool = this_client->lpool;
|
tsmpool* lpool = this_client->lpool;
|
||||||
if(NMUX_DEBUG) fprintf(stderr, "client 0x%x: socket = %d!\n", (intptr_t)param, this_client->socket);
|
if(NMUX_DEBUG) fprintf(stderr, "client %p: socket = %d!\n", param, this_client->socket);
|
||||||
|
|
||||||
if(NMUX_DEBUG) fprintf(stderr, "client 0x%x: poll init...", (intptr_t)param);
|
if(NMUX_DEBUG) fprintf(stderr, "client %p: poll init...", param);
|
||||||
struct pollfd pollfds[1];
|
struct pollfd pollfds[1];
|
||||||
pollfds[0].fd = this_client->socket;
|
pollfds[0].fd = this_client->socket;
|
||||||
pollfds[0].events = POLLOUT;
|
pollfds[0].events = POLLOUT;
|
||||||
|
@ -307,10 +313,10 @@ void* client_thread (void* param)
|
||||||
// (Wait for the server process to wake me up.)
|
// (Wait for the server process to wake me up.)
|
||||||
while(!pool_read_buffer || client_buffer_index >= lpool->size)
|
while(!pool_read_buffer || client_buffer_index >= lpool->size)
|
||||||
{
|
{
|
||||||
if(NMUX_DEBUG) fprintf(stderr, "client 0x%x: trying to grb\n", (intptr_t)param);
|
if(NMUX_DEBUG) fprintf(stderr, "client %p: trying to grb\n", param);
|
||||||
pool_read_buffer = (char*)lpool->get_read_buffer(this_client->tsmthread);
|
pool_read_buffer = (char*)lpool->get_read_buffer(this_client->tsmthread);
|
||||||
if(pool_read_buffer) { client_buffer_index = 0; break; }
|
if(pool_read_buffer) { client_buffer_index = 0; break; }
|
||||||
if(NMUX_DEBUG) fprintf(stderr, "client 0x%x: cond_waiting for more data\n", (intptr_t)param);
|
if(NMUX_DEBUG) fprintf(stderr, "client %p: cond_waiting for more data\n", param);
|
||||||
pthread_mutex_lock(&wait_mutex);
|
pthread_mutex_lock(&wait_mutex);
|
||||||
this_client->sleeping = 1;
|
this_client->sleeping = 1;
|
||||||
pthread_cond_wait(&wait_condition, &wait_mutex);
|
pthread_cond_wait(&wait_condition, &wait_mutex);
|
||||||
|
@ -318,14 +324,14 @@ void* client_thread (void* param)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Wait for the socket to be available for write.
|
//Wait for the socket to be available for write.
|
||||||
if(NMUX_DEBUG) fprintf(stderr, "client 0x%x: polling for socket write...", (intptr_t)param);
|
if(NMUX_DEBUG) fprintf(stderr, "client %p: polling for socket write...", param);
|
||||||
int ret = poll(pollfds, 1, -1);
|
int ret = poll(pollfds, 1, -1);
|
||||||
if(NMUX_DEBUG) fprintf(stderr, "client polled for socket write.\n");
|
if(NMUX_DEBUG) fprintf(stderr, "client polled for socket write.\n");
|
||||||
if(ret == 0) continue;
|
if(ret == 0) continue;
|
||||||
else if (ret == -1) { client_goto_source = 1; goto client_thread_exit; }
|
else if (ret == -1) { client_goto_source = 1; goto client_thread_exit; }
|
||||||
|
|
||||||
//Read data from global tsmpool and write it to client socket
|
//Read data from global tsmpool and write it to client socket
|
||||||
if(NMUX_DEBUG) fprintf(stderr, "client 0x%x: sending...", (intptr_t)param);
|
if(NMUX_DEBUG) fprintf(stderr, "client %p: sending...", param);
|
||||||
ret = send(this_client->socket, pool_read_buffer + client_buffer_index, lpool->size - client_buffer_index, MSG_NOSIGNAL);
|
ret = send(this_client->socket, pool_read_buffer + client_buffer_index, lpool->size - client_buffer_index, MSG_NOSIGNAL);
|
||||||
if(NMUX_DEBUG) fprintf(stderr, "client sent.\n");
|
if(NMUX_DEBUG) fprintf(stderr, "client sent.\n");
|
||||||
if(ret == -1)
|
if(ret == -1)
|
||||||
|
@ -340,7 +346,7 @@ void* client_thread (void* param)
|
||||||
}
|
}
|
||||||
|
|
||||||
client_thread_exit:
|
client_thread_exit:
|
||||||
fprintf(stderr, "client 0x%x: CS_THREAD_FINISHED, client_goto_source = %d, errno = %d", (intptr_t)param, client_goto_source, errno);
|
fprintf(stderr, "client %p: CS_THREAD_FINISHED, client_goto_source = %d, errno = %d", param, client_goto_source, errno);
|
||||||
this_client->status = CS_THREAD_FINISHED;
|
this_client->status = CS_THREAD_FINISHED;
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -42,7 +42,7 @@ tsmthread_t* tsmpool::register_thread()
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsmpool::remove_thread(tsmthread_t* thread)
|
void tsmpool::remove_thread(tsmthread_t* thread)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&this->mutex);
|
pthread_mutex_lock(&this->mutex);
|
||||||
for(int i=0;i<threads.size();i++)
|
for(int i=0;i<threads.size();i++)
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
tsmpool(size_t size, int num);
|
tsmpool(size_t size, int num);
|
||||||
void* get_write_buffer();
|
void* get_write_buffer();
|
||||||
tsmthread_t* register_thread();
|
tsmthread_t* register_thread();
|
||||||
int remove_thread(tsmthread_t* thread);
|
void remove_thread(tsmthread_t* thread);
|
||||||
void* get_read_buffer(tsmthread_t* thread);
|
void* get_read_buffer(tsmthread_t* thread);
|
||||||
int index_next(int index) { return (index+1==num)?0:index+1; }
|
int index_next(int index) { return (index+1==num)?0:index+1; }
|
||||||
int index_before(int index) { return (index-1<0)?num-1:index-1; }
|
int index_before(int index) { return (index-1<0)?num-1:index-1; }
|
||||||
|
|
Loading…
Reference in a new issue