dem DBname (int n, dem x, dem y) { if (y == NULL) return NULL; if (x == y) return var(n); if (node(y) == node_ap) return ap (DBname (n, x, sd0(y)), DBname (n, x, sd1(y))); if (node(y) == node_lambda) return lambda (DBname (n+1, x, sd0(y))); /* return y; */ return mkdem (node(y), level(y), name(y), DBname (n, x, sd0(y)), DBname (n, x, sd1(y))); }
void stat_counter_index_object_t::test<9>() { LLSimpleStatMMM<F64> m1; typedef LLSimpleStatMMM<F64>::Value lcl_float; lcl_float zero(0); // Insert overflowing values const lcl_float bignum(F64_MAX / 2); m1.record(bignum); m1.record(bignum); m1.record(bignum); m1.record(bignum); m1.record(bignum); m1.record(bignum); m1.record(bignum); m1.record(zero); ensure("Overflowed MMM<F64> has 8 count", (8 == m1.getCount())); ensure("Overflowed MMM<F64> has 0 min", (zero == m1.getMin())); ensure("Overflowed MMM<F64> has huge max", (bignum == m1.getMax())); ensure("Overflowed MMM<F64> has fetchable mean", (1.0 == m1.getMean() || true)); // We should be infinte but not interested in proving the IEEE standard here. LLSD sd1(m1.getMean()); // std::cout << "Thingy: " << m1.getMean() << " and as LLSD: " << sd1 << std::endl; ensure("Overflowed MMM<F64> produces LLSDable Real", (sd1.isReal())); }
TEST(JsonTest, LoadMalformed) { ScopedDevice sd1(sample_malformed); ASSERT_EQ(sd1.device, nullptr); ASSERT_EQ(sd1.error.type, MB_DEVICE_JSON_PARSE_ERROR); ASSERT_EQ(sd1.error.line, 1); ASSERT_EQ(sd1.error.column, 1); }
K init(K x) { dumb_socketpair(sockets, 0); sd1(sockets[1], recieve_data); FEED_STATE = FF_CONTINUE_FEED; start_thread(); return (K) 0; }
dem lr (int r, dem d) { dem d1; if (d->_lr[r] != NULL) return d->_lr[r]; switch (node(d)) { case node_ap : d1 = mkdem (node_ap, 0, NULL, lr (r, sd0(d)), lr (r, sd1(d))); break; case node_transym : if (lr (0, sd0(d)) == lr (0, sd1(d))) d1 = lr (1, d->_subdem[r]); else d1 = mkdem (node_var, 0, NULL, NULL, NULL); /* d1 = lr (r, sd0(d)); */ break; case node_symbol : case node_var : d1 = d; break; case node_lambda : d1 = mkdem (node_lambda, 0, NULL, lr (r, sd0(d)), NULL); break; case node_subst : if (r == 0) d1 = mkdem (node_ap, 0, NULL, mkdem (node_lambda, 0, NULL, sd0(d), NULL), sd1(d)); else d1 = subst (0, sd0(d), sd1(d)); break; case node_axiom : d1 = d->_subdem[r]; break; default : d1 = d; break; } d->_lr[r] = d1; return d1; }
void storeSimple() { SimpleData sd1(4); // single data instance std::ofstream out("simple.dat", std::ios::binary); // standard C++ file stream boost::archive::binary_oarchive arch(out); // write binary output to file std::cout << "Storing data (" << sd1.num << ")" << std::endl; arch << sd1; }
dem subst (int n, dem y, dem z) { if (y == NULL) return NULL; if (node(y) == node_var) { if (level(y) == n) return z; if (level(y) > n) return mkdem (node_var, level(y)-1, NULL, NULL, NULL); } if (node(y) == node_ap) return ap (subst (n, sd0(y), z), subst (n, sd1(y), z)); if (node(y) == node_lambda) return lambda (subst (n+1, sd0(y), shift (0, 1, z))); /* return y; */ return mkdem (node(y), level(y), name(y), subst (n, sd0(y), z), subst (n, sd1(y), z)); }
TEST(JsonTest, LoadMultiple) { ScopedDevices sd1(sample_multiple); ASSERT_NE(sd1.devices, nullptr); ScopedDevices sd2(sample_complete); ASSERT_EQ(sd2.devices, nullptr); ASSERT_EQ(sd2.error.type, MB_DEVICE_JSON_MISMATCHED_TYPE); ASSERT_STREQ(sd2.error.context, "."); ASSERT_STREQ(sd2.error.actual_type, "object"); ASSERT_STREQ(sd2.error.expected_type, "array"); }
TEST(JsonTest, CreateJson) { ScopedDevice sd1(sample_complete); ASSERT_NE(sd1.device, nullptr); std::unique_ptr<char, void (*)(void *)> json( mb_device_to_json(sd1.device), free); ASSERT_TRUE(json.operator bool()); ScopedDevice sd2(json.get()); ASSERT_TRUE(mb_device_equals(sd1.device, sd2.device)); }
print (dem d) { if (d == NULL) { printf ("<NULL>"); return; } if (d->_name != NULL) { printf ("%s ", d->_name); return; } switch (node(d)) { case node_ap : printf ("-"); sd01: print (sd0(d)); print (sd1(d)); break; case node_transym : printf ("/"); goto sd01; case node_symbol : printf ("%s ", d->_name); break; case node_var : printf ("%d ", d->_level); break; case node_lambda : printf ("\\"); print (sd0(d)); break; case node_subst : printf ("%"); goto sd01; case node_axiom : printf ("#"); goto sd01; default : printf ("?%d,", node(d)); goto sd01; } }
TEST(JsonTest, LoadInvalidType) { ScopedDevice sd1(sample_invalid_root); ASSERT_EQ(sd1.device, nullptr); ASSERT_EQ(sd1.error.type, MB_DEVICE_JSON_MISMATCHED_TYPE); ASSERT_STREQ(sd1.error.context, "."); ASSERT_STREQ(sd1.error.actual_type, "array"); ASSERT_STREQ(sd1.error.expected_type, "object"); ScopedDevice sd2(sample_invalid_type); ASSERT_EQ(sd2.device, nullptr); ASSERT_EQ(sd2.error.type, MB_DEVICE_JSON_MISMATCHED_TYPE); ASSERT_STREQ(sd2.error.context, ".boot_ui"); ASSERT_STREQ(sd2.error.actual_type, "string"); ASSERT_STREQ(sd2.error.expected_type, "object"); }
dem shift (int m, int n, dem x) { if (x == NULL) return NULL; if (node(x) == node_var) if (level(x) >= m) return var (level(x)+n); else return x; if (node(x) == node_lambda) return lambda (shift (m+1, n, sd0(x))); if (node(x) == node_var || node(x) == node_symbol) return mkdem (node(x), level(x), name(x), NULL, NULL); return mkdem (node(x), level(x), NULL, shift (m, n, sd0(x)), shift (m, n, sd1(x))); }
TEST(JsonTest, LoadInvalidValue) { ScopedDevice sd1(sample_invalid_device_flags); ASSERT_EQ(sd1.device, nullptr); ASSERT_EQ(sd1.error.type, MB_DEVICE_JSON_UNKNOWN_VALUE); ASSERT_STREQ(sd1.error.context, ".flags[0]"); ScopedDevice sd2(sample_invalid_tw_flags); ASSERT_EQ(sd2.device, nullptr); ASSERT_EQ(sd2.error.type, MB_DEVICE_JSON_UNKNOWN_VALUE); ASSERT_STREQ(sd2.error.context, ".boot_ui.flags[0]"); ScopedDevice sd3(sample_invalid_tw_pixel_format); ASSERT_EQ(sd3.device, nullptr); ASSERT_EQ(sd3.error.type, MB_DEVICE_JSON_UNKNOWN_VALUE); ASSERT_STREQ(sd3.error.context, ".boot_ui.pixel_format"); ScopedDevice sd4(sample_invalid_tw_force_pixel_format); ASSERT_EQ(sd4.device, nullptr); ASSERT_EQ(sd4.error.type, MB_DEVICE_JSON_UNKNOWN_VALUE); ASSERT_STREQ(sd4.error.context, ".boot_ui.force_pixel_format"); }
K threads_init(K x) { unsigned char bytes[]={0x01,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x65,0x13}; K s=ktn(KG,sizeof(bytes));memcpy(kG(s),bytes,sizeof(bytes)); if(!okx(s))R krr("serialization");value_fn=d9(s); if(!(threadpool=threadpool_create(NUMTHREADS,QUEUESIZE,0)))R krr("threadpool"); if(pipe(mainloop_pipe)==-1)R krr("pipe");sd1(mainloop_pipe[0],threads_q_callback);R(K)0;}
int main() { RakNet::RakPeerInterface *rakPeer[2]; rakPeer[0]=RakNet::RakPeerInterface::GetInstance(); rakPeer[1]=RakNet::RakPeerInterface::GetInstance(); RakNet::SocketDescriptor sd1(50000,0),sd2(50002,0); rakPeer[0]->Startup(1,&sd1, 1); rakPeer[1]->Startup(1,&sd2, 1); rakPeer[1]->SetMaximumIncomingConnections(1); RakNet::UDPForwarder udpForwarder; printf("Demonstrates the UDP Forwarder class\n"); printf("It routes datagrams from system to another, at the UDP level.\n"); printf("You probably won't use UDPForwarder directly.\n"); printf("See UDPProxyClient, UDPProxyServer, UDPProxyCoordinator.\n"); // Start the forwarder udpForwarder.Startup(); // RakNet will send a message at least every 5 seconds. Add another second to account for thread latency const RakNet::TimeMS timeoutOnNoDataMS=6000; // Address is probably 192.168.0.1. Fix it to be 127.0.0.1. // Only necessary to do this when connecting through the loopback on the local system. In a real system we'd stick with the external IP RakNet::SystemAddress peer0Addr = rakPeer[0]->GetMyBoundAddress(); RakAssert(peer0Addr!=RakNet::UNASSIGNED_SYSTEM_ADDRESS); RakNet::SystemAddress peer1Addr = rakPeer[1]->GetMyBoundAddress(); RakAssert(peer1Addr!=RakNet::UNASSIGNED_SYSTEM_ADDRESS); // peer0Addr.FromString("127.0.0.1"); // peer1Addr.FromString("127.0.0.1"); unsigned short fowardPort; if (!udpForwarder.StartForwarding(peer0Addr,peer1Addr, timeoutOnNoDataMS, 0, AF_INET, &fowardPort,0)) { printf("Socket error\n"); return 1; } // Send a connect message to the forwarder, on the port to forward to rakPeer[1] rakPeer[0]->Connect(peer1Addr.ToString(false), fowardPort, 0, 0); printf("'q'uit.\n"); RakNet::Packet *p; while (1) { for (int i=0; i < 2 ; i++) { p=rakPeer[i]->Receive(); while (p) { if (p->data[0]==ID_DISCONNECTION_NOTIFICATION) printf("%s disconnected\n", p->systemAddress.ToString(true)); else if (p->data[0]==ID_CONNECTION_LOST) printf("Lost connection to %s (failure)\n", p->systemAddress.ToString(true)); else if (p->data[0]==ID_NO_FREE_INCOMING_CONNECTIONS) printf("%s has no free incoming connections.\n", p->systemAddress.ToString(true)); else if (p->data[0]==ID_NEW_INCOMING_CONNECTION) printf("%s connected to us (success)\n", p->systemAddress.ToString(true)); else if (p->data[0]==ID_CONNECTION_REQUEST_ACCEPTED) printf("Connection request accepted from %s (success)\n", p->systemAddress.ToString(true)); else if (p->data[0]==ID_CONNECTION_ATTEMPT_FAILED) printf("Failed to connect to %s (failure)\n", p->systemAddress.ToString(true)); rakPeer[i]->DeallocatePacket(p); p=rakPeer[i]->Receive(); } } udpForwarder.Update(); if (kbhit()) { char ch = getch(); if (ch=='q' || ch=='Q') break; } RakSleep(30); } rakPeer[0]->Shutdown(100,0); rakPeer[1]->Shutdown(100,0); RakNet::RakPeerInterface::DestroyInstance(rakPeer[0]); RakNet::RakPeerInterface::DestroyInstance(rakPeer[1]); return 0; }
int main() { printf("This sample demonstrates incrementally sending a file with\n"); printf("the FileListTransferPlugin. Incremental sends will read and send the.\n"); printf("file only as needed, rather than putting the whole file in memory.\n"); printf("This is to support sending large files to many users at the same time.\n"); printf("Difficulty: Intermediate\n\n"); TestCB testCB; RakNet::FileListTransfer flt1, flt2; #ifdef USE_TCP RakNet::PacketizedTCP tcp1, tcp2; #if RAKNET_SUPPORT_IPV6==1 const bool testInet6=true; #else const bool testInet6=false; #endif if (testInet6) { tcp1.Start(60000,1,-99999,AF_INET6); tcp2.Start(60001,1,-99999,AF_INET6); tcp2.Connect("::1",60000,false,AF_INET6); } else { tcp1.Start(60000,1,-99999,AF_INET); tcp2.Start(60001,1,-99999,AF_INET); tcp2.Connect("127.0.0.1",60000,false,AF_INET); } tcp1.AttachPlugin(&flt1); tcp2.AttachPlugin(&flt2); #else RakNet::RakPeerInterface *peer1 = RakNet::RakPeerInterface::GetInstance(); RakNet::RakPeerInterface *peer2 = RakNet::RakPeerInterface::GetInstance(); RakNet::SocketDescriptor sd1(60000,0),sd2(60001,0); peer1->Startup(1,&sd1,1); peer2->Startup(1,&sd2,1); peer1->SetMaximumIncomingConnections(1); peer2->Connect("127.0.0.1",60000,0,0,0); peer1->AttachPlugin(&flt1); peer2->AttachPlugin(&flt2); peer1->SetSplitMessageProgressInterval(9); peer2->SetSplitMessageProgressInterval(9); #endif // Print sending progress notifications flt1.AddCallback(&testFileListProgress); // Run incremental reads in a thread so the read does not block the main thread flt1.StartIncrementalReadThreads(1); RakNet::FileList fileList; RakNet::IncrementalReadInterface incrementalReadInterface; printf("Enter complete filename with path to test:\n"); char str[256]; Gets(str, sizeof(str)); if (str[0]==0) strcpy(str, "D:\\RakNet\\Lib\\RakNetLibStaticDebug.lib"); file=str; fileCopy=file+"_copy"; // Reference this file, rather than add it in memory. Will send 1000 byte chunks. The reason to do this is so the whole file does not have to be in memory at once unsigned int fileLength = GetFileLength(file.C_String()); if (fileLength==0) { printf("Test file %s not found.\n", file.C_String()); #ifdef USE_TCP #else RakNet::RakPeerInterface::DestroyInstance(peer1); RakNet::RakPeerInterface::DestroyInstance(peer2); #endif return 1; } fileList.AddFile(file.C_String(), file.C_String(), 0, fileLength, fileLength, FileListNodeContext(0,0), true); // Wait for the connection printf("File added.\n"); RakSleep(100); RakNet::Packet *packet1, *packet2; while (1) { #ifdef USE_TCP RakNet::SystemAddress sa; sa=tcp2.HasCompletedConnectionAttempt(); if (sa!=RakNet::UNASSIGNED_SYSTEM_ADDRESS) { flt2.SetupReceive(&testCB, false, sa); break; } #else // Wait for the connection request to be accepted packet2=peer2->Receive(); if (packet2 && packet2->data[0]==ID_CONNECTION_REQUEST_ACCEPTED) { flt2.SetupReceive(&testCB, false, packet2->systemAddress); peer2->DeallocatePacket(packet2); break; } peer2->DeallocatePacket(packet2); #endif RakSleep(30); } // When connected, send the file. Since the file is a reference, it will be sent incrementally while (1) { #ifdef USE_TCP packet1=tcp1.Receive(); packet2=tcp2.Receive(); RakNet::SystemAddress sa; sa = tcp1.HasNewIncomingConnection(); if (sa!=RakNet::UNASSIGNED_SYSTEM_ADDRESS) flt1.Send(&fileList,0,sa,0,HIGH_PRIORITY,0, &incrementalReadInterface, 2000 * 1024); tcp1.DeallocatePacket(packet1); tcp2.DeallocatePacket(packet2); #else packet1=peer1->Receive(); packet2=peer2->Receive(); if (packet1 && packet1->data[0]==ID_NEW_INCOMING_CONNECTION) flt1.Send(&fileList,peer1,packet1->systemAddress,0,HIGH_PRIORITY,0, &incrementalReadInterface, 2000000); peer1->DeallocatePacket(packet1); peer2->DeallocatePacket(packet2); #endif RakSleep(0); } #ifdef USE_TCP #else RakNet::RakPeerInterface::DestroyInstance(peer1); RakNet::RakPeerInterface::DestroyInstance(peer1); #endif return 0; }
void executeFileRexxCls::saveInStackFun(void) { savedInCallFunctionCls sd1(indexCurProcedure,curExeProc->getNameProc(),curExeProc,getNameFile()); socaf.push(sd1); }
ZS con(){Q(sslGetProperty(c,SSL_OPT_CHANNEL_FD,&d),"getfd")sd1(d,d0);R 0;}