#endif
#define MAX_HOSTNAME 256
-#define RINGBUF_SIZE 65536*8
-#define FRESH_QUEUE_SIZE 1024
+#define RINGBUF_SIZE 1024*1024
+#define FRESH_QUEUE_SIZE 4096
#define WAIT 100*1000 /* ¥Ö¥é¥¦¥ºÂ¦¤Î¥¦¥¨¥¤¥È(usñ°Ì) */
#define DEFAULT_DELAY 50
+#define RECVBUF_SIZE 1024
static int sd; /* ¥½¥±¥Ã¥È¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿ */
-static long epoch_time; /* ³«»Ï»þ¹ï */
+static long epoch_time; /* ¥Ð¥Ã¥Õ¥¡³«»Ï»þ¹ï */
static long time_diff; /* ¥×¥ì¥¤Â¦¤È¤Î»þ´Ö¤Î¤º¤ì(¤³¤ì¤ò¸«¤Ê¤¬¤é¥Ç¥£¥ì¥¤¤òÄ´À°¤·¤Æ¤¤¤¯) */
static int browse_delay; /* ɽ¼¨¤¹¤ë¤Þ¤Ç¤Î»þ´Ö(100msñ°Ì)(¤³¤Î´Ö¤Ë¥é¥°¤òµÛ¼ý¤¹¤ë) */
static int server_port;
{
term *t = angband_term[0];
- if (!chuukei_server) return;
+ if (!chuukei_server) return;
chuukei_server = FALSE;
static long get_current_time(void)
{
#ifdef WINDOWS
- return GetTickCount() / 100;
+ return timeGetTime() / 100;
#elif defined(MACINTOSH)
return TickCount();
#else
if (chuukei_server) disable_chuukei_server();
else chuukei_client = FALSE;
- prt("¥Ð¥Ã¥Õ¥¡¤¬°î¤ì¤Þ¤·¤¿¡£¥µ¡¼¥Ð¤È¤ÎÀܳ¤òÀÚÃǤ·¤Þ¤¹¡£", 0, 0);
+ prt("Á÷¼õ¿®¥Ð¥Ã¥Õ¥¡¤¬°î¤ì¤Þ¤·¤¿¡£¥µ¡¼¥Ð¤È¤ÎÀܳ¤òÀÚÃǤ·¤Þ¤¹¡£", 0, 0);
inkey();
close(sd);
#ifndef MACINTOSH
fd_set fdset;
struct timeval tv;
- int writen = 0;
if (!chuukei_server) return;
ring.rptr += result;
ring.inlen -= result;
- writen += result;
if (ring.rptr == RINGBUF_SIZE) ring.rptr = 0;
if (ring.inlen == 0) break;
}
#else
- struct timeval tv;
- int writen = 0;
-
if (!chuukei_server) return;
if (ring.inlen == 0) return;
- tv.tv_sec = 0;
- tv.tv_usec = 0;
-
while (1)
{
- struct timeval tmp_tv;
int result;
- tmp_tv = tv;
-
/* ¥½¥±¥Ã¥È¤Ë¥Ç¡¼¥¿¤ò½ñ¤¹þ¤á¤ë¤«¤É¤¦¤«Ä´¤Ù¤ë */
result = OTSnd(ep, ring.buf + ring.rptr, ((ring.wptr > ring.rptr ) ? ring.wptr : RINGBUF_SIZE) - ring.rptr, 0);
ring.rptr += result;
ring.inlen -= result;
- writen += result;
if (ring.rptr == RINGBUF_SIZE) ring.rptr = 0;
if (ring.inlen == 0) break;
return (-1);
}
- epoch_time = get_current_time();
-
return (0);
#else /* MACINTOSH */
OSStatus err;
sndCall.addr.len = sizeof(InetAddress);
sndCall.addr.buf = (unsigned char*) &inAddr;
- sndCall.opt.buf = nil; /* no connection options */
+ sndCall.opt.buf = nil; /* no connection options */
sndCall.opt.len = 0;
- sndCall.udata.buf = nil; /* no connection data */
+ sndCall.udata.buf = nil; /* no connection data */
sndCall.udata.len = 0;
- sndCall.sequence = 0; /* ignored by OTConnect */
+ sndCall.sequence = 0; /* ignored by OTConnect */
err = OTConnect(ep, &sndCall, NULL);
{
char buf[1024];
- (void)v;
-
if (n == TERM_XTRA_CLEAR || n == TERM_XTRA_FRESH || n == TERM_XTRA_SHAPE)
{
sprintf(buf, "x%c", n+1);
}
+static int handle_timestamp_data(int timestamp)
+{
+ long current_time = get_current_time();
+
+ /* ÉÁ²è¥¥å¡¼¤Ï¶õ¤«¤É¤¦¤«¡© */
+ if (fresh_queue.tail == fresh_queue.next)
+ {
+ /* ¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤·»Ï¤á¤Î»þ´Ö¤òÊݸ¤·¤Æ¤ª¤¯ */
+ epoch_time = current_time;
+ epoch_time += browse_delay;
+ epoch_time -= timestamp;
+ time_diff = current_time - timestamp;
+ }
+
+ /* ÉÁ²è¥¥å¡¼¤ËÊݸ¤·¡¢Êݸ°ÌÃÖ¤ò¿Ê¤á¤ë */
+ fresh_queue.time[fresh_queue.tail] = timestamp;
+ fresh_queue.tail ++;
+
+ /* ¥¥å¡¼¤ÎºÇ¸åÈø¤ËÅþ㤷¤¿¤éÀèƬ¤ËÌ᤹ */
+ fresh_queue.tail %= FRESH_QUEUE_SIZE;
+
+ if (fresh_queue.tail == fresh_queue.next)
+ {
+ /* ÉÁ²è¥¥å¡¼°î¤ì */
+ prt("ÉÁ²è¥¿¥¤¥ß¥ó¥°¥¥å¡¼¤¬°î¤ì¤Þ¤·¤¿¡£¥µ¡¼¥Ð¤È¤ÎÀܳ¤òÀÚÃǤ·¤Þ¤¹¡£", 0, 0);
+ inkey();
+ close(sd);
+
+ return -1;
+ }
+
+ /* ¥×¥ì¥¤Â¦¤È¤Î¥Ç¥£¥ì¥¤¤òÄ´À° */
+ if (time_diff != current_time - timestamp)
+ {
+ long old_time_diff = time_diff;
+ time_diff = current_time - timestamp;
+ epoch_time -= (old_time_diff - time_diff);
+ }
+
+ /* Success */
+ return 0;
+}
+
static int read_sock(void)
{
- char buf[1024];
+ static char recv_buf[RECVBUF_SIZE];
+ static int remain_bytes = 0;
+ int recv_bytes;
int i;
- for (i = 0;; i++)
- {
- if (recv(sd, buf+i, 1, 0) <= 0)
- return -1;
+ /* Á°²ó»Ä¤Ã¤¿¥Ç¡¼¥¿¤Î¸å¤Ë¤Ä¤Å¤±¤ÆÇÛ¿®¥µ¡¼¥Ð¤«¤é¥Ç¡¼¥¿¼õ¿® */
+ recv_bytes = recv(sd, recv_buf + remain_bytes, RECVBUF_SIZE - remain_bytes, 0);
+ if (recv_bytes <= 0)
+ return -1;
- if (buf[i] == '\0')
- {
- if (buf[0] == 'd')
- {
- int timestamp = atoi(buf + 1);
- long current_time = get_current_time();
-
- /* ºÇ½é¤Î»þ´Ö¤òÊݸ¤·¤Æ¤ª¤¯ */
- if (!fresh_queue.time[0])
- {
- epoch_time = current_time;
- epoch_time += browse_delay;
- epoch_time -= timestamp;
- time_diff = current_time - timestamp;
- }
-
- fresh_queue.time[fresh_queue.tail] = timestamp;
- fresh_queue.tail ++;
-
- if (fresh_queue.tail == FRESH_QUEUE_SIZE)
- fresh_queue.tail = 0;
-
- /* ¥×¥ì¥¤Â¦¤È¤Î¥Ç¥£¥ì¥¤¤òÄ´À° */
- if (time_diff > current_time - timestamp)
- {
- long old_time_diff = time_diff;
- time_diff = current_time - timestamp;
- epoch_time -= (old_time_diff - time_diff);
- }
-
- if (fresh_queue.tail == fresh_queue.next)
- {
- /* queue°î¤ì */
- close(sd);
- exit(1);
- }
+ /* Á°²ó»Ä¤Ã¤¿¥Ç¡¼¥¿Î̤˺£²óÆɤó¤À¥Ç¡¼¥¿Î̤òÄɲà */
+ remain_bytes += recv_bytes;
- }
+ for (i = 0; i < remain_bytes; i ++)
+ {
+ /* ¥Ç¡¼¥¿¤Î¤¯¤®¤ê('\0')¤òõ¤¹ */
+ if (recv_buf[i] == '\0')
+ {
+ /* 'd'¤Ç»Ï¤Þ¤ë¥Ç¡¼¥¿(¥¿¥¤¥à¥¹¥¿¥ó¥×)¤Î¾ì¹ç¤Ï
+ ÉÁ²è¥¥å¡¼¤ËÊݸ¤¹¤ë½èÍý¤ò¸Æ¤Ö */
+ if ((recv_buf[0] == 'd') &&
+ (handle_timestamp_data(atoi(recv_buf + 1)) < 0))
+ return -1;
- if (insert_ringbuf(buf) < 0)
+ /* ¼õ¿®¥Ç¡¼¥¿¤òÊݸ */
+ if (insert_ringbuf(recv_buf) < 0)
return -1;
- return (i);
+
+ /* ¼¡¤Î¥Ç¡¼¥¿°Ü¹Ô¤òrecv_buf¤ÎÀèƬ¤Ë°ÜÆ° */
+ memmove(recv_buf, recv_buf + i + 1, remain_bytes - i - 1);
+
+ remain_bytes -= (i+1);
+ i = 0;
}
}
+
+ return 0;
}
#ifndef WINDOWS
-/* WinÈǤÎÃæÅÀ¤ÈÊɤÎƦÉå¤ò¥Ô¥ê¥ª¥É¤È¥·¥ã¡¼¥×¤Ë¤¹¤ë¡£ */
+/* WinÈǤÎÃæÅÀ¤ÈÊɤÎƦÉå¤ò¥Ô¥ê¥ª¥É¤È¥·¥ã¡¼¥×¤Ë¤¹¤ë¡£*/
static void win2unix(int col, char *buf)
{
char kabe;
if (!chuukei_client && fresh_queue.next == fresh_queue.tail ) break;
}
#else
- struct timeval tv;
-
- tv.tv_sec = 0;
- tv.tv_usec = WAIT;
-
Term_clear();
Term_fresh();
Term_xtra(TERM_XTRA_REACT, 0);
while (1)
{
- struct timeval tmp_tv;
UInt32 unreadData = 0;
int n;
-
- if (flush_ringbuf_client()) continue;
- tmp_tv = tv;
+ if (flush_ringbuf_client()) continue;
/* ¥½¥±¥Ã¥È¤Ë¥Ç¡¼¥¿¤¬Íè¤Æ¤¤¤ë¤«¤É¤¦¤«Ä´¤Ù¤ë */
-
+
OTCountDataBytes(ep, &unreadData);
if(unreadData <= 0 ){
Term_xtra(TERM_XTRA_FLUSH, 0);