[Mit-cadr-cvs] r381 - trunk/emulator/usim
ggilley at common-lisp.net
ggilley at common-lisp.net
Sat Dec 1 19:21:14 UTC 2012
Author: ggilley
Date: Sat Dec 1 11:21:14 2012
New Revision: 381
Log:
handle quit during dired viewing
Modified:
trunk/emulator/usim/Files.c
trunk/emulator/usim/chaos.c
trunk/emulator/usim/chaos.h
Modified: trunk/emulator/usim/Files.c
==============================================================================
--- trunk/emulator/usim/Files.c Sat Dec 1 09:47:53 2012 (r380)
+++ trunk/emulator/usim/Files.c Sat Dec 1 11:21:14 2012 (r381)
@@ -858,7 +858,7 @@
case DATOP:
break;
default:
- log(LOG_ERR, "FILE: Bad op: 0%o\n", ((packet->opcode & 0xff00) >> 8));
+ printf("FILE: Bad op: 0%o\n", ((packet->opcode & 0xff00) >> 8));
tfree(t);
return TNULL;
}
@@ -2354,7 +2354,6 @@
return;
}
derror:
- printf("diropen error: %d\n", errcode);
error(t, t->t_fh->f_name, errcode);
x->x_state = X_DERROR;
#if defined(OSX)
@@ -2558,6 +2557,7 @@
void
fileclose(register struct xfer *x, register struct transaction *t)
{
+ log(LOG_INFO, "FILE: fileclose\n");
x->x_flags |= X_CLOSE;
switch (x->x_options & (O_READ | O_WRITE | O_DIRECTORY | O_PROPERTIES)) {
case O_READ:
@@ -2590,6 +2590,12 @@
#if 0
(void)signal(SIGHUP, SIG_IGN);
#endif
+
+ // we may have a packet stuck waiting to transmit
+ // force the transmit window to close and tickle the connection
+ if (x->x_options & O_READ)
+ chaos_interrupt_connection(x->x_fh->f_connection);
+
#if defined(OSX)
dispatch_semaphore_signal(x->x_hangsem);
#else
@@ -2611,7 +2617,9 @@
char response[CHMAXDATA];
int errcode = 0;
struct tm *tm;
-
+
+ log(LOG_INFO, "FILE: xclose\n");
+
if (x->x_options & (O_DIRECTORY|O_PROPERTIES)) {
respond(t, NOSTR);
return;
@@ -4719,7 +4727,8 @@
xpweof(register struct xfer *x)
{
chaos_packet *packet = chaos_allocate_packet(x->x_fh->f_connection, CHAOS_OPCODE_EOF, 0);
- chaos_connection_queue(x->x_fh->f_connection, packet);
+ if (chaos_connection_queue(x->x_fh->f_connection, packet))
+ return -1;
return 0;
}
@@ -4745,7 +4754,8 @@
chaos_packet *packet = chaos_allocate_packet(conn, x->x_op, len);
memcpy(packet->data, x->x_pkt.cp_data, len);
- chaos_connection_queue(conn, packet);
+ if (chaos_connection_queue(conn, packet))
+ return -1;
return 0;
}
Modified: trunk/emulator/usim/chaos.c
==============================================================================
--- trunk/emulator/usim/chaos.c Sat Dec 1 09:47:53 2012 (r380)
+++ trunk/emulator/usim/chaos.c Sat Dec 1 11:21:14 2012 (r381)
@@ -522,7 +522,6 @@
static packet_queue *queuehead;
static packet_queue *queuetail;
-static chaos_packet *lastpacket;
int connectionstate = 0;
#if defined(OSX)
@@ -602,10 +601,10 @@
conn->queuesem = dispatch_semaphore_create(0);
conn->twsem = dispatch_semaphore_create(0);
#else
- pthread_mutex_init(&conn->queuesem, NULL);
- pthread_cond_init(&conn->queuecond, NULL);
- pthread_mutex_init(&conn->twsem, NULL);
- pthread_cond_init(&conn->twcond, NULL);
+ pthread_mutex_init(&conn->queuesem, NULL);
+ pthread_cond_init(&conn->queuecond, NULL);
+ pthread_mutex_init(&conn->twsem, NULL);
+ pthread_cond_init(&conn->twcond, NULL);
#endif
conn->lastreceived = 0;
conn->lastsent = 0;
@@ -667,7 +666,19 @@
free(conn);
}
-void chaos_connection_queue(chaos_connection *conn, chaos_packet *packet)
+void chaos_interrupt_connection(chaos_connection *conn)
+{
+ conn->remotelastreceived = conn->lastsent;
+#if defined(OSX)
+ dispatch_semaphore_signal(conn->twsem);
+#else
+ pthread_mutex_lock(&conn->twsem);
+ pthread_cond_signal(&conn->twsem);
+ pthread_mutex_unlock(&conn->twsem);
+#endif
+}
+
+int chaos_connection_queue(chaos_connection *conn, chaos_packet *packet)
{
packet_queue *node;
unsigned short nextpacket;
@@ -686,11 +697,11 @@
#if defined(OSX)
if (dispatch_semaphore_wait(conn->twsem, dispatch_time(DISPATCH_TIME_NOW, 5LL * NSEC_PER_SEC)))
{
- if (lastpacket)
+ if (conn->lastpacket)
{
printf("re-transmit last packet\n");
- chaos_packet *retransmit = lastpacket;
- lastpacket = 0;
+ chaos_packet *retransmit = conn->lastpacket;
+ conn->lastpacket = 0;
chaos_queue(retransmit);
}
}
@@ -719,8 +730,9 @@
if ((packet->opcode >> 8) != CHAOS_OPCODE_STS && packet->destindex == conn->remoteindex && cmp_gt(packet->number, conn->lastsent))
conn->lastsent = packet->number;
+ conn->lastpacket = packet;
chaos_queue(packet);
- return;
+ return 0;
}
node = malloc(sizeof(packet_queue));
@@ -739,7 +751,7 @@
if (conn->orderhead == 0)
conn->orderhead = node;
pthread_mutex_unlock(&conn->queuelock);
- return;
+ return 0;
}
{
@@ -758,6 +770,7 @@
pthread_cond_signal(&conn->queuecond);
pthread_mutex_unlock(&conn->queuesem);
#endif
+ return 0;
}
chaos_packet *chaos_connection_dequeue(chaos_connection *conn)
@@ -1009,10 +1022,6 @@
chaos_rcv_buffer[size + 2] = 0; // unused checksum
size += 3;
- if (lastpacket)
- free(lastpacket);
- lastpacket = packet;
-
// ignore any packets not to us
if (dest_addr != chaos_addr)
return 0;
@@ -1258,6 +1267,12 @@
if (cmp_gt(packet->acknowledgement, conn->remotelastreceived))
conn->remotelastreceived = packet->acknowledgement;
+ if (conn->lastpacket && conn->remotelastreceived == conn->lastpacket->number)
+ {
+ free(conn->lastpacket);
+ conn->lastpacket = 0;
+ }
+
conn->state = cs_open;
conn->twsize = *(unsigned short *)&packet->data[2];
#if CHAOS_DEBUG
@@ -1266,14 +1281,17 @@
#if defined(OSX)
dispatch_semaphore_signal(conn->twsem);
#else
- pthread_mutex_lock(&conn->twsem);
- pthread_cond_signal(&conn->twcond);
- pthread_mutex_unlock(&conn->twsem);
+ pthread_mutex_lock(&conn->twsem);
+ pthread_cond_signal(&conn->twcond);
+ pthread_mutex_unlock(&conn->twsem);
#endif
}
return 0;
}
-
+ if (conn && (packet->opcode >> 8) == CHAOS_OPCODE_CLS)
+ {
+ printf("chaos: got close\n");
+ }
if (conn && (cmp_gt(conn->lastreceived, packet->number) || (conn->lastreceived == packet->number)))
{
#if CHAOS_DEBUG
Modified: trunk/emulator/usim/chaos.h
==============================================================================
--- trunk/emulator/usim/chaos.h Sat Dec 1 09:47:53 2012 (r380)
+++ trunk/emulator/usim/chaos.h Sat Dec 1 11:21:14 2012 (r381)
@@ -124,17 +124,19 @@
#endif
packet_queue *orderhead;
packet_queue *ordertail;
+ chaos_packet *lastpacket;
} chaos_connection;
void chaos_queue(chaos_packet *packet);
chaos_connection *chaos_make_connection(void);
void chaos_delete_connection(chaos_connection *conn);
chaos_connection *chaos_find_connection(unsigned short index);
-void chaos_connection_queue(chaos_connection *conn, chaos_packet *packet);
+int chaos_connection_queue(chaos_connection *conn, chaos_packet *packet);
chaos_packet *chaos_connection_dequeue(chaos_connection *conn);
chaos_connection *chaos_open_connection(int co_host, char *contact, int mode, int async, int rwsize);
chaos_packet *chaos_allocate_packet(chaos_connection *conn, int opcode, ssize_t len);
void chaos_dump_connection(chaos_connection *conn);
+void chaos_interrupt_connection(chaos_connection *conn);
#endif // OSX
More information about the mit-cadr-cvs
mailing list