botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
bsProxyUtils.c File Reference

BotSense bsProxy utilities. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/netmsgs.h"
#include "botsense/BotSense.h"
#include "botsense/bsProxyMsgs.h"
#include "bsProxy.h"

Go to the source code of this file.

Functions

uint_t timer_elapsed (struct timeval *pTvMark)
 Calculate the elapsed time between the given time mark and this call. More...
 
void BsProxyLogMsgHdr (const char *sPreface, BsProxyMsgHdr_T *pMsgHdr)
 Log message header. More...
 

Detailed Description

BotSense bsProxy utilities.

LastChangedDate
2010-08-20 11:36:38 -0600 (Fri, 20 Aug 2010)
Rev
568
Author
Robin Knight (robin.nosp@m..kni.nosp@m.ght@r.nosp@m.oadn.nosp@m.arrow.nosp@m.s.co.nosp@m.m)

Definition in file bsProxyUtils.c.

Function Documentation

void BsProxyLogMsgHdr ( const char *  sPreface,
BsProxyMsgHdr_T pMsgHdr 
)

Log message header.

Parameters
sPrefacePreface string.
pMsgHdrPointer to message header structure.

Definition at line 108 of file bsProxyUtils.c.

References BSPROXY_VCONN_SERVER, BsProxyLookupMsgDef(), BsProxyMsgHdr_T::m_hdrBodyLen, BsProxyMsgHdr_T::m_hdrMagic, BsProxyMsgHdr_T::m_hdrMsgId, BsProxyMsgHdr_T::m_hdrTid, and BsProxyMsgHdr_T::m_hdrVConn.

Referenced by ClientSetTraceState().

109 {
110  FILE *fp;
111  const NMMsgDef_T *pMsgDef;
112  const char *sMsgName;
113 
114  fp = LOG_GET_LOGFP();
115 
116  if( pMsgHdr != NULL )
117  {
118  if( pMsgHdr->m_hdrVConn == BSPROXY_VCONN_SERVER )
119  {
120  pMsgDef = BsProxyLookupMsgDef((BsProxyMsgId_T)pMsgHdr->m_hdrMsgId);
121  sMsgName = pMsgDef!=NULL? pMsgDef->m_sMsgName: "";
122  }
123  else
124  {
125  sMsgName = "";
126  }
127  fprintf(fp, "%s MsgHdr = {\n", sPreface);
128  fprintf(fp, " Magic: 0x%04x\n", pMsgHdr->m_hdrMagic);
129  fprintf(fp, " Tid: %u\n", (uint_t)(pMsgHdr->m_hdrTid));
130  fprintf(fp, " VConn: %u\n", (uint_t)(pMsgHdr->m_hdrVConn));
131  fprintf(fp, " MsgId: %u %s\n", pMsgHdr->m_hdrMsgId, sMsgName);
132  fprintf(fp, " BodyLen: %u\n", pMsgHdr->m_hdrBodyLen);
133  fprintf(fp, "}\n");
134  }
135  else
136  {
137  fprintf(fp, "%s MsgHdr: (null)\n", sPreface);
138  }
139 }
const NMMsgDef_T * BsProxyLookupMsgDef(BsProxyMsgId_T eMsgId)
Look up the message definition associated with the message id.
Definition: bsProxyMsgs.c:874
#define BSPROXY_VCONN_SERVER
handle for server-terminated msgs
Definition: BotSense.h:140
ushort_t m_hdrBodyLen
message body length
Definition: BotSense.h:284
ushort_t m_hdrMsgId
message id (vConnection unique)
Definition: BotSense.h:283
ushort_t m_hdrMagic
"unique" magic pattern
Definition: BotSense.h:280
BsProxyMsgId_T
Definition: bsProxyMsgs.h:35
byte_t m_hdrTid
transaction id
Definition: BotSense.h:281
byte_t m_hdrVConn
virtual connection handle (server unique)
Definition: BotSense.h:282
uint_t timer_elapsed ( struct timeval *  pTvMark)

Calculate the elapsed time between the given time mark and this call.

Parameters
pTvMarkPointer to timeval holding time mark.
Returns
Number of microseconds elasped. If the marked time is invalid or the current time cannot be ascertained, UINT_MAX is returned.

Definition at line 79 of file bsProxyUtils.c.

References timer_mark().

Referenced by timer_mark().

80 {
81  struct timeval tvEnd, tvDelta;
82 
83  timer_mark(&tvEnd);
84 
85  if( !timerisset(pTvMark) || !timerisset(&tvEnd) )
86  {
87  return UINT_MAX;
88  }
89 
90  tvDelta.tv_sec = tvEnd.tv_sec - pTvMark->tv_sec;
91  if( tvEnd.tv_usec < pTvMark->tv_usec )
92  {
93  tvDelta.tv_sec--;
94  tvEnd.tv_usec += 1000000;
95  }
96  tvDelta.tv_usec = tvEnd.tv_usec - pTvMark->tv_usec;
97 
98  return (uint_t)(tvDelta.tv_sec * 1000000 + tvDelta.tv_usec);
99 }
static void timer_mark(struct timeval *pTvMark)
Mark the current time. Resolution is microseconds.
Definition: bsLibClient.c:340