int C_MessageQueue::recv_message(T_Message *msg) { if (m_newmsg_pos>=PAD8(m_newmsg.message_length)) { ::memcpy(msg,&m_newmsg,sizeof(m_newmsg)); ::memset(&m_newmsg,0,sizeof(m_newmsg)); m_stat_recv++; m_newmsg_pos=-1; return 0; } return 1; }
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - email : [email protected] - github : https://github.com/powturbo - homepage : https://sites.google.com/site/powturbo/ - twitter : https://twitter.com/powturbo bitpack.c - "Integer Compression" binary packing **/ #include "bitpack_.h" #include "bitpack.h" #define IPPB( __ip,__x, __parm) #define PAD8(__x) ( (((__x)+8-1)/8) ) unsigned char *bitpack32(unsigned *__restrict__ in, int n, int nb, unsigned char *__restrict__ out) { unsigned char *pout = out+PAD8(n*nb); BITPACK32(in, n, nb, out, 0); return pout; } unsigned char *bitpack16(unsigned short *__restrict__ in, int n, int nb, unsigned char *__restrict__ out) { unsigned char *pout = out+PAD8(n*nb); BITPACK32(in, n, nb, out, 0); return pout; }
#include __FILE__ #define BITUNBLKV32_0(ip, i, __op, __parm) {\ _mm_storeu_si128(__op++, __parm);\ _mm_storeu_si128(__op++, __parm);\ _mm_storeu_si128(__op++, __parm);\ _mm_storeu_si128(__op++, __parm);\ _mm_storeu_si128(__op++, __parm);\ _mm_storeu_si128(__op++, __parm);\ _mm_storeu_si128(__op++, __parm);\ _mm_storeu_si128(__op++, __parm);\ } #define BITUNPACK0(__parm) __parm = _mm_setzero_si128() unsigned char *bitunpackv32( unsigned char *__restrict in, unsigned n, unsigned *__restrict out, unsigned b) { unsigned char *ip = in+PAD8(n*b); __m128i sv; BITUNPACKV32(in, n, b, out, sv); return ip; } #undef VSTO #undef BITUNPACK0 //------------------------------------------------------ #define VSTO(__op, i, __ov, __sv) __ov = UNZIGZAG128_32(__ov); SCAN128_32(__ov,__sv); _mm_storeu_si128(__op++, __sv) #include __FILE__ #define BITUNPACK0(__parm) unsigned char *bitzunpackv32( unsigned char *__restrict in, unsigned n, unsigned *__restrict out, unsigned start, unsigned b) { unsigned char *ip = in+PAD8(n*b);
void C_MessageQueue::run(int isrecv, int maxbytesend) { // recieve message if (isrecv) { if (m_newmsg_pos==-1) { if (m_con->recv_bytes_available() >= 40) { unsigned char t[8]; m_con->recv_bytes(&m_newmsg.message_md5,16); m_con->recv_bytes(t,8); m_newmsg.message_type=t[0]|(t[1]<<8)|(t[2]<<16)|(t[3]<<24); m_newmsg.message_prio=t[4]; m_newmsg.message_length=t[5]|(t[6]<<8); m_newmsg.message_ttl=t[7]; m_con->recv_bytes(&m_newmsg.message_guid,16); if (!m_newmsg.message_type || m_newmsg.message_ttl > G_MAX_TTL || m_newmsg.message_length < 0 || m_newmsg.message_length > MESSAGE_MAX_PAYLOAD_ROUTE || (MESSAGE_TYPE_BCAST(m_newmsg.message_type) && m_newmsg.message_length > MESSAGE_MAX_PAYLOAD_BCAST) ) { debug_printf("queue::run() got bad message type=%d, prio=%d, ttl=%d, len=%d\n", m_newmsg.message_type,m_newmsg.message_prio,m_newmsg.message_ttl,m_newmsg.message_length); m_newmsg.message_length=0; m_con->close(1); return; } m_newmsg.data=new C_SHBuf(m_newmsg.message_length); if (!m_newmsg.data->Get()) { delete m_newmsg.data; m_newmsg.message_length=0; m_con->close(1); return; } m_newmsg.data->Lock(); m_newmsg_pos=0; } } int padlen=PAD8(m_newmsg.message_length); if (m_newmsg_pos >= 0 && m_newmsg_pos < padlen) { int len=padlen-m_newmsg_pos; int len2=m_con->recv_bytes_available(); if (len > len2) len=len2; if (len > 0) { m_con->recv_bytes((char*)m_newmsg.data->Get()+m_newmsg_pos,len); m_newmsg_pos+=len; } if (m_newmsg_pos >= padlen) // finish crc calculation { unsigned char buf[16]; calc_md5(&m_newmsg,buf); if (memcmp(buf,m_newmsg.message_md5,16)) { debug_printf("queue::run() got bad message (MD5 differs) type=%d, prio=%d, ttl=%d, len=%d\n", m_newmsg.message_type,m_newmsg.message_prio,m_newmsg.message_ttl,m_newmsg.message_length); m_newmsg.message_length=0; m_newmsg_pos=-1; m_con->close(1); return; } } } } else { int do_saturate=(g_throttle_flag&32) && (m_con->get_saturatemode()&1); int satsize=min(m_con->getMaxSendSize()/64,216); if (satsize < 4) satsize=4; if (!m_msg_used && do_saturate && m_con->send_bytes_in_queue() < 40+satsize*2 && (maxbytesend < 0 || m_con->send_bytes_in_queue()+40+satsize < maxbytesend)) saturate(satsize); while (m_msg_used>0 && (maxbytesend<0 || m_con->send_bytes_in_queue() < maxbytesend)) { if (m_msg_bsent<0) { if (m_con->send_bytes_available() >= 40) { unsigned char t[8]; m_con->send_bytes(&m_msg->message_md5,16); t[0]=m_msg->message_type&0xff; t[1]=(m_msg->message_type>>8)&0xff; t[2]=(m_msg->message_type>>16)&0xff; t[3]=(m_msg->message_type>>24)&0xff; t[4]=m_msg->message_prio; t[5]=m_msg->message_length&0xff; t[6]=(m_msg->message_length>>8)&0xff; t[7]=m_msg->message_ttl; m_con->send_bytes(t,8); m_con->send_bytes(&m_msg->message_guid,16); m_msg_bsent=0; if (MESSAGE_TYPE_BCAST(m_msg->message_type) && m_msg->message_length > MESSAGE_MAX_PAYLOAD_BCAST) { debug_printf("queue::run() send bcast payload length of %d too large\n",m_msg->message_length); } else if (m_msg->message_length > MESSAGE_MAX_PAYLOAD_ROUTE) { debug_printf("queue::run() send route/local payload length of %d too large\n",m_msg->message_length); } } else break; } if (m_msg_bsent>=0) { int len=PAD8(m_msg->message_length)-m_msg_bsent; int len2=m_con->send_bytes_available(); if (len > len2) len=len2; if (len >= 8) { m_con->send_bytes((char*)m_msg->data->Get()+m_msg_bsent,len); m_msg_bsent += len; } if (m_msg_bsent >= m_msg->message_length) { m_msg_bsent=-1; removefirst(); if (!m_msg_used && do_saturate && m_con->send_bytes_available() >= 40+satsize && m_con->send_bytes_in_queue() < 40+satsize*2 && (maxbytesend < 0 || m_con->send_bytes_in_queue()+40+satsize < maxbytesend)) saturate(satsize); } if (len2 < 8) break; } }