)
{
struct refclockproc * pp;
- u_char clktype;
int unit;
unit = p->refclkunit;
l_fp *tsptr /* pointer to timestamp returned */
)
{
- char s[BMAX];
- char *dpt, *dpend, *dp;
+ const char *sp, *spend;
+ char *dp, *dpend;
+ int dlen;
- dpt = s;
- dpend = s + refclock_gtraw(rbufp, s, BMAX - 1, tsptr);
- if (dpend - dpt > bmax - 1)
- dpend = dpt + bmax - 1;
- for (dp = lineptr; dpt < dpend; dpt++) {
- char c;
+ if (bmax <= 0)
+ return (0);
+
+ dp = lineptr;
+ dpend = dp + bmax - 1; /* leave room for NUL pad */
+ sp = (const char *)rbufp->recv_buffer;
+ spend = sp + rbufp->recv_length;
- c = *dpt & 0x7f;
+ while (sp != spend && dp != dpend) {
+ char c;
+
+ c = *sp++ & 0x7f;
if (c >= 0x20 && c < 0x7f)
*dp++ = c;
}
- if (dp == lineptr)
- return (0);
-
- *dp = '\0';
- return (dp - lineptr);
+ /* Get length of data written to the destination buffer. If
+ * zero, do *not* place a NUL byte to preserve the previous
+ * buffer content.
+ */
+ dlen = dp - lineptr;
+ if (dlen)
+ *dp = '\0';
+ *tsptr = rbufp->recv_time;
+ DPRINTF(2, ("refclock_gtlin: fd %d time %s timecode %d %s\n",
+ rbufp->fd, ulfptoa(&rbufp->recv_time, 6), dlen,
+ lineptr));
+ return (dlen);
}
l_fp *tsptr /* pointer to timestamp returned */
)
{
- char *dpt, *dpend, *dp;
- int i;
-
- dpt = (char *)rbufp->recv_buffer;
- dpend = dpt + rbufp->recv_length;
+ if (bmax <= 0)
+ return (0);
+ bmax -= 1; /* leave room for trailing NUL */
+ if (bmax > rbufp->recv_length)
+ bmax = rbufp->recv_length;
+ memcpy(lineptr, rbufp->recv_buffer, bmax);
+ lineptr[bmax] = '\0';
- /*
- * Copy the raw buffer to the user string. The string is padded
- * with a NUL, which is not included in the character count.
- */
- if (dpend - dpt > bmax - 1)
- dpend = dpt + bmax - 1;
- for (dp = lineptr; dpt < dpend; dpt++)
- *dp++ = *dpt;
- *dp = '\0';
- i = dp - lineptr;
*tsptr = rbufp->recv_time;
DPRINTF(2, ("refclock_gtraw: fd %d time %s timecode %d %s\n",
- rbufp->fd, ulfptoa(&rbufp->recv_time, 6), i,
+ rbufp->fd, ulfptoa(&rbufp->recv_time, 6), bmax,
lineptr));
- return (i);
+ return (bmax);
}
}
+/*
+ * process_refclock_packet()
+ *
+ * Used for deferred processing of 'io_input' on systems where threading
+ * is used (notably Windows). This is acting as a trampoline to make the
+ * real calls to the refclock functions.
+ */
+void
+process_refclock_packet(
+ struct recvbuf * rb
+ )
+{
+ struct refclockio * rio;
+
+ /* get the refclockio structure from the receive buffer */
+ rio = &rb->recv_peer->procptr->io;
+
+ /* call 'clock_recv' if either there is no input function or the
+ * raw input function tells us to feed the packet to the
+ * receiver.
+ */
+ if (rio->io_input == NULL || (*rio->io_input)(rb) != 0) {
+ rio->recvcount++;
+ packets_received++;
+ handler_pkts++;
+ (*rio->clock_recv)(rb);
+ }
+}
+
+
/*
* The following code does not apply to WINNT & VMS ...
*/
struct recvbuf *rbufp
)
{
- struct parseunit *parse = (struct parseunit *)((void *)rbufp->recv_srcclock);
- parsetime_t parsetime;
+ struct parseunit * parse;
+ parse = (struct parseunit *)rbufp->recv_peer->procptr->unitptr;
if (!parse->peer)
return;
struct recvbuf *rbufp
)
{
- struct parseunit *parse = (struct parseunit *)((void *)rbufp->recv_srcclock);
+ struct parseunit * parse;
+
int count;
unsigned char *s;
timestamp_t ts;
+ parse = (struct parseunit *)rbufp->recv_peer->procptr->unitptr;
if (!parse->peer)
return 0;
struct recvbuf *rbufp
)
{
- struct parseunit *parse = (struct parseunit *)((void *)rbufp->recv_srcclock);
+ struct parseunit * parse;
parsetime_t parsetime;
+ parse = (struct parseunit *)rbufp->recv_peer->procptr->unitptr;
if (!parse->peer)
return;
/*
* pick correct input machine
*/
- parse->generic->io.srcclock = (void *)parse;
+ parse->generic->io.srcclock = peer;
parse->generic->io.datalen = 0;
parse->binding = init_iobinding(parse);
*/
if (!errstatus && Bytes) {
buff->recv_length = (int) Bytes;
- buff->receiver = rio->clock_recv;
+ buff->receiver = process_refclock_packet;
buff->dstadr = NULL;
buff->recv_peer = rio->srcclock;
/*
buff->recv_time = cr_time;
buff->recv_length = 0;
buff->fd = rio->fd;
- buff->receiver = rio->clock_recv;
+ buff->receiver = process_refclock_packet;
buff->dstadr = NULL;
buff->recv_peer = rio->srcclock;
- consumed = indicate_refclock_packet(rio, buff);
- if (!consumed) {
- packets_received++;
- handler_pkts++;
- }
+ add_full_recv_buffer(buff);
+ SetEvent(WaitableIoEventHandle);
buff = get_free_recv_buffer_alloc();
}
}
rbufp->recv_length = (int)octets;
rbufp->dstadr = NULL;
rbufp->recv_time = arrival_time;
- rbufp->receiver = rio->clock_recv;
+ rbufp->receiver = process_refclock_packet;
rbufp->recv_peer = rio->srcclock;
rbufp->fd = rio->fd; /* was handle */
- consumed = indicate_refclock_packet(rio, rbufp);
- if (!consumed) {
- rio->recvcount++;
- packets_received++;
- handler_pkts++;
- }
+ add_full_recv_buffer(rbufp);
+ SetEvent(WaitableIoEventHandle);
rbufp = get_free_recv_buffer_alloc();
}