void sqlinc::check_error() { // if an error occurs, display the error and quit the program if (errno()) { cerr << "Error " << errno() << ": " << error() << endl; exit(0); } }
int rtsp_init_tcpControl(int port) { struct sockaddr_in inaddr; int sockfd sockfd = socket(AF_INET, SOCK_STREAM, 0);//tcp if (sockfd == INVALID_SOCKET) { public_err("create socket failed : %s\n", strerror(errno())); sockfd = -1; goto EXIT; } int ret = -1; memset(&inaddr, 0, sizeof(inaddr)); inaddr.sin_family = AF_INET; inaddr.sin_addr.s_addr = htonl(INADDR_ANY); inaddr.sin_port = htons(port); ret = bind(sockfd, (struct sockaddr*)&inaddr, sizeof(inaddr)); if (-1 == ret) { public_err("bind socket to address failed : %s\n", strerror(errno())); close(sockfd); sockfd = -1; goto EXIT; } ret = listen(sockfd, 128);//内核中建立队列 if (-1 == ret) { public_err("listen socket failed : %s\n", strerror(errno())); close(sockfd); sockfd = -1; goto EXIT; } public_info("rtsp server demo starting on port %d\n", port); EXIT: return sockfd; }
static void * slab_map(size_t length) { static int mmap_fd = -1; void *res; #if ! MAP_ANON if (mmap_fd < 0) { mmap_fd = open("/dev/zero", 0); if (mmap_fd < 0) log_module(MAIN_LOG, LOG_FATAL, "Unable to open /dev/zero for mmap: %s", strerror(errno())); } #endif res = mmap(0, length, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, mmap_fd, 0); if (res == MAP_FAILED) log_module(MAIN_LOG, LOG_FATAL, "Unable to mmap %lu bytes (%s).", (unsigned long)length, strerror(errno)); return res; }
bool Chain::substituent_m ( const int& l1, //start pos of c const int& u1, //end pos of c const int& l2, //start pos of this const int& u2, //end pos of this const Chain* c, vector<cMatchType>& result //result ) const { if (!result.empty ()) result.clear (); assert (l1 <= u1 + 1); assert (l2 <= u2 + 1); // take case! l1 = u1+1 and l2 = u2+1 has been ruled out previously if (l1 == u1 + 1) { if (l2 == u2 + 1) return true; else return false; } if (l2 == u2 + 1) { if (l1 == u1 + 1) return true; else { cMatchType res; for (int i=l1; i <= u1; i++) { string partRef = c->listOfParts[i]->getPartRef (); int keyValue = getKeywords (partRef); if (keyValue != -1) { switch (keyValue) { case 0: case 1: {res.push_back (make_pair(l2,u2));break;} default: return false; } } else { string errno ("Invalid Substituent Type: "); errno += partRef + "!"; throw CoreException (errno); } } result.push_back (res); return true; } } // // only handle one part and left recuisively // int startpos, endpos; assert (l1 < c->listOfParts.size ()); string partRef = c->listOfParts[l1]->getPartRef (); string partType = c->listOfParts[l1]->getPartType (); int keyValue = getKeywords (partRef); if (keyValue != -1) { switch (keyValue) { case 0: { startpos = l2; endpos = u2+1; if (!partType.empty ()) { for (int i=l2; i<=u2; i++) if (!type_match (listOfParts[i]->partType, partType)) endpos = i; break; } break; } case 1: { startpos = l2; endpos = u2+1; for (int i=l2; i<=u2; i++) { if (listOfParts[i]->isBinded) endpos = i; break; } if (!partType.empty ()) { for (int i=l2; i<= endpos-1; i++) { if (!type_match (listOfParts[i]->partType, partType)) endpos = i; break; } } break; } case 2: { startpos = l2+1; endpos = u2+1; if (!partType.empty ()) { for (int i=l2; i<=u2; i++) if (!type_match (listOfParts[i]->partType, partType)) endpos = i; break; } break; } case 3: { startpos = l2+1; endpos = u2+1; for (int i=l2; i<=u2; i++) { if (listOfParts[i]->isBinded) endpos = i; break; } if (!partType.empty ()) { for (int i=l2; i<= endpos-1; i++) { if (!type_match (listOfParts[i]->partType, partType)) endpos = i; break; } } break; } case 4: { startpos = endpos = l2+1; if (!type_match (listOfParts[l2]->partType, partType)) endpos = l2; break; } case 5: { startpos = endpos = l2+1; if (listOfParts[l2]->isBinded) endpos = l2; if (!type_match (listOfParts[l2]->partType, partType)) endpos = l2; break; } default: break; } } else { string errno ("Invalid Substituent Type: "); errno += partRef + "!"; throw CoreException (errno); } bool rVal = false; for (int i = startpos; i <= endpos; i++) { vector< list< pair<int,int> > > recursive; bool mok = substituent_m (l1+1, u1, i, u2, c, recursive); if (mok) { if (recursive.size () == 0) { // only push back in matchings of current part cMatchType only_one; only_one.push_back (make_pair (l2, i-1)); result.push_back (only_one); } else { for (int j=0; j < recursive.size (); j++) { recursive[j].push_front (make_pair (l2, i-1)); result.push_back (recursive[j]); } } rVal = true; } else continue; } return rVal; }