byte buffer[]=new byte[1024];
int length=cs.read(buffer);
String st=(new String(buffer)).subString(0, length);
- cs.room.sendToRoom(cs, st.getBytes());
+ Message m=new Message(st, cs){};
+}
+
+task SendMessage(Message m{!Sent}) {
+ m.cs.room.sendToRoom(m.cs,m.st.getBytes());
+ taskexit(m {Sent});
}
byte buffer[]=new byte[1024];
int length=sock.read(buffer);
String st=(new String(buffer)).subString(0, length);
- System.printString(st);
- System.printString("\n");
- System.printInt(length);
- System.printString("\n");
room.sendToRoom(this, st.getBytes());
}
public class Inventory {
- // Inventory flags
- flag TransInitialize;
-
// Transaction variables
int numitems;
HashMap map;
public class Logger {
- //Logger flag
- flag Initialize;
FileOutputStream fos;
return -1;
}
+ public String replace(char oldch, char newch) {
+ char[] buffer=new char[count];
+ for(int i=0;i<count;i++) {
+ char x=charAt(i);
+ if (x==oldch)
+ x=newch;
+ buffer[i]=x;
+ }
+ return new String(buffer);
+ }
+
public int indexOf(int ch) {
return this.indexOf(ch, 0);
}
for(i=0;i<oldcurrentsize;i++) {
struct genpointerlist * tmpptr=oldbins[i];
while(tmpptr!=NULL) {
- int hashcode=genhashfunction(ht, tmpptr->src);
+ unsigned int hashcode=genhashfunction(ht, tmpptr->src);
struct genpointerlist *nextptr=tmpptr->next;
tmpptr->next=newbins[hashcode];
newbins[hashcode]=tmpptr;
}
void genrehash(struct genhashtable * ht) {
- /* Expand hashtable */
struct genpointerlist **newbins=(struct genpointerlist **) RUNMALLOC(sizeof (struct genpointerlist *)*ht->currentsize);
struct genpointerlist **oldbins=ht->bins;
long j,i;
for(i=0;i<ht->currentsize;i++) {
struct genpointerlist * tmpptr=oldbins[i];
while(tmpptr!=NULL) {
- int hashcode=genhashfunction(ht, tmpptr->src);
+ unsigned int hashcode=genhashfunction(ht, tmpptr->src);
struct genpointerlist *nextptr=tmpptr->next;
tmpptr->next=newbins[hashcode];
newbins[hashcode]=tmpptr;
}
if (hasflags[type]) {
(((void **)cpy)[2])=flagptr;
- flagorand(cpy, 1, 0xFFFFFFFF);
+ flagorandinit(cpy, 0, 0xFFFFFFFF);
}
}
}
initializemmap();
#endif
processOptions();
-
+ initializeexithandler();
/* Create table for failed tasks */
failedtasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd,
(int (*)(void *,void *)) &comparetpd);
if (FD_ISSET(fd, &tmpreadfds)) {
/* Set ready flag on object */
void * objptr;
+ // printf("Setting fd %d\n",fd);
if (RuntimeHashget(fdtoobject, fd,(int *) &objptr)) {
flagorand(objptr,1,0xFFFFFFFF); /* Set the first flag to 1 */
}
#endif
+void exithandler(int sig, siginfo_t *info, void * uap) {
+ exit(0);
+}
+
+void initializeexithandler() {
+ struct sigaction sig;
+ sig.sa_sigaction=&exithandler;
+ sig.sa_flags=SA_SIGINFO;
+ sigemptyset(&sig.sa_mask);
+ sigaction(SIGUSR2, &sig, 0);
+}
+
+
/* This function inject failures */
void injectinstructionfailure() {
struct ___String___ * NewString(const char *str,int length);
#endif
+void initializeexithandler();
void failedboundschk();
void failednullptr();
void abort_task();
if (bytewritten!=length) {
perror("ERROR IN NATIVEWRITE");
+ printf("Supposed to write %d, wrote %d\n", length, bytewritten);
}
break;
}
struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
#endif
#endif
- int byteread=read(fd, charstr, length);
+ int byteread;
+
+ // printf("Doing read on %d\n",fd);
+ while(1) {
+ byteread=read(fd, charstr, length);
+
+ break;
+ }
#ifdef THREADS
#ifdef PRECISE_GC
restartaftergc(tmp);
#endif
#endif
-
+
{
int i;
for(i=0;i<byteread;i++) {
if (byteread<0) {
printf("ERROR IN NATIVEREAD\n");
- return 0;
+ perror("");
+ byteread=0;
}
#ifdef TASK
flagorand(VAR(___this___),0,0xFFFFFFFE);
pthread_cond_init(&objcond,NULL);
pthread_key_create(&threadlocks, NULL);
processOptions();
+ initializeexithandler();
sig.sa_sigaction=&threadhandler;
sig.sa_flags=SA_SIGINFO;