本文整理汇总了C++中HeaderList::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ HeaderList::begin方法的具体用法?C++ HeaderList::begin怎么用?C++ HeaderList::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HeaderList
的用法示例。
在下文中一共展示了HeaderList::begin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
void CsvFile::write(const HeaderList& header, const DataMap& data) throw (FileException)
{
std::ofstream file(filename.c_str());
if (!file) throw FileException("Cannot open file", filename, __FUNCTION_NAME__);
// Print raw of headers
for (HeaderList::const_iterator it = header.begin(); it != header.end(); ++it)
{
file << separator << *it;
}
// End of line
file << std::endl;
// Print all data raws
for (DataMap::const_iterator rawit = data.begin() ; rawit != data.end(); ++rawit)
{
file<< rawit->first;
for (DataRaw::const_iterator it = rawit->second.begin(); it != rawit->second.end(); ++it)
{
if (*it > 0)
file << separator << *it;
else
file << separator;
}
// End of line
file << std::endl;
}
};
示例2: receive_request
bool CHttpServer::receive_request(ByteVector &request)
{
if (verbose) RAWTRACE("Receiving request...");
ByteVector r;
char buf[BUF_SIZE];
int attempts = 0;
for(;;) {
if (verbose) RAWTRACE("Read portion of data from socket...");
int n = recv(m_sock, &buf[0], sizeof(buf), 0);
//RAWTRACE1("RECV: %d", n);
if (n == -1) {
int e = RHO_NET_ERROR_CODE;
if (verbose) RAWTRACE1("RECV ERROR: %d", e);
#if !defined(WINDOWS_PLATFORM)
if (e == EINTR)
continue;
#else
if (e == WSAEINTR)
continue;
#endif
#if defined(OS_WP8) || (defined(RHODES_QT_PLATFORM) && defined(OS_WINDOWS_DESKTOP)) || defined(OS_WINCE)
if (e == EAGAIN || e == WSAEWOULDBLOCK) {
#else
if (e == EAGAIN) {
#endif
if (!r.empty())
break;
if(++attempts > (HTTP_EAGAIN_TIMEOUT*10))
{
if (verbose) RAWLOG_ERROR("Error when receiving data from socket. Client does not send data for " HTTP_EAGAIN_TIMEOUT_STR " sec. Cancel recieve.");
return false;
}
fd_set fds;
FD_ZERO(&fds);
FD_SET(m_sock, &fds);
timeval tv = {0};
tv.tv_usec = 100000;//100 MS
select(m_sock + 1, &fds, 0, 0, &tv);
continue;
}
if (verbose) RAWLOG_ERROR1("Error when receiving data from socket: %d", e);
return false;
}
if (n == 0) {
if(!r.empty()) {
if (verbose) RAWTRACE("Client closed connection gracefully");
break;
} else {
if (verbose) RAWLOG_ERROR("Connection gracefully closed before we receive any data");
return false;
}
} else {
if (verbose) RAWTRACE1("Actually read %d bytes", n);
r.insert(r.end(), &buf[0], &buf[0] + n);
}
}
if (!r.empty()) {
request.insert(request.end(), r.begin(), r.end());
if ( !rho_conf_getBool("log_skip_post") ) {
String strRequest(request.begin(),request.end());
if (verbose) RAWTRACE1("Received request:\n%s", strRequest.c_str());
}
}
return true;
}
bool CHttpServer::send_response_impl(String const &data, bool continuation)
{
#ifdef OS_MACOSX
if ( m_localResponseWriter != 0 ) {
m_localResponseWriter->writeResponse( data );
return true;
}
#endif
if (verbose) {
if (continuation)
if (verbose) RAWTRACE("Send continuation data...");
else
if (verbose) RAWTRACE("Sending response...");
}
// First of all, make socket blocking
#if defined(WINDOWS_PLATFORM)
unsigned long optval = 0;
if(::ioctlsocket(m_sock, FIONBIO, &optval) == SOCKET_ERROR) {
RAWLOG_ERROR1("Can not set blocking socket mode: %d", RHO_NET_ERROR_CODE);
return false;
}
#else
int flags = fcntl(m_sock, F_GETFL);
if (flags == -1) {
if (verbose) RAWLOG_ERROR1("Can not get current socket mode: %d", errno);
//.........这里部分代码省略.........
示例3: read
void CsvFile::read(HeaderList& header, DataMap& data) const throw (FileException, CustomException)
{
std::ifstream file(filename.c_str());
if (!file) throw FileException("Cannot open file", filename, __FUNCTION_NAME__);
// a buffer to store the line read
std::string line;
if ( ! std::getline(file, line))
throw FileException("Cannot get the first line of file", filename, __FUNCTION_NAME__);
unsigned int pointer = 0;
unsigned int rawnb = 0;
std::string word ="";
int localHostColNumber = -1, tmp=0;
bool uselocalhost=false;
bool useotherthanlocalhost=false;
// Parse the first line (header line)
while(pointer < line.size())
{
while( pointer < line.size() && line[pointer] != separator)
{
//remove white spaces
if (line[pointer] != ' ')
{
word.push_back(line[pointer]);
}
pointer++;
}
if( !word.empty())
{
// warning if id already in
if (std::find(header.begin(), header.end(), word) != header.end() )
{
// Was error before, now just a warning: may be convenient to have several time the same name in a header
Msg::warning("Duplicate header element '"+ word+"' in file "+filename, __FUNCTION_NAME__);
// throw FileException("Duplicate header elements'"+ word+"'",filename, __FUNCTION_NAME__);
}
header.push_back(word);
tmp++;
}
// if we have "localhost" in csv file, note the column number.
if(word == "localhost" || word == "Localhost" || word == "127.0.0.1")
localHostColNumber = tmp;
pointer++;
word.clear();
}
// Parse the lines
while (std::getline(file, line))
{
rawnb++;
pointer = 0;
bool firstWord = true; // Are we parsing the first column
unsigned int column = 0; // Which column is being scanned?
std::string id;
while(line.size() > pointer)
{
// get word
word.clear();
while(line.size() > pointer && line[pointer] != separator)
{
if (line[pointer] != ' ')
word.push_back(line[pointer]);
pointer++;
}
pointer++;
if (firstWord)
{
// it's the map id
if ( word.empty() ) break; // forget about this line and go to parse next line
id = word;
if(data.find(id) != data.end())
throw CustomException("Component : " + id + " is specified twice in CSV file.", __FUNCTION_NAME__ );
// init the raw of this id with zeros.
data[id].insert(data[id].begin(), header.size(),0);
firstWord = false;
}
else
{
if (!word.empty())
{
// store data
try{
data[id].at(column) = convertTo<int>(word);
if (data[id].at(column) > 0)// one component instance at least mapped
{
if(column == localHostColNumber-1) // we are reading in a locahost column
{
// Remember that we have one component mapped on a localHost.
uselocalhost=true;
//.........这里部分代码省略.........
示例4: ngx_http_cxxmvc_handler
static ngx_int_t ngx_http_cxxmvc_handler(ngx_http_request_t *r)
{
using dragon::kHttp_Method_Get;
using dragon::kResponseTypeRedirect;
using dragon::HeaderList;
using dragon::CookieList;
using dragon::StringRef;
using dragon::HttpRequest;
using dragon::HttpResponse;
ngx_buf_t *buf = NULL;
ngx_chain_t out;
unsigned uriLen = r->uri.len;
if (r->args.len > 0)
uriLen = r->uri.len + r->args.len + 1;
struct sockaddr_in *sin;
ngx_addr_t addr;
addr.sockaddr = r->connection->sockaddr;
addr.socklen = r->connection->socklen;
sin = (struct sockaddr_in *)addr.sockaddr;
char *ip = inet_ntoa(sin->sin_addr);
StringRef IP(ip, strlen(ip));
StringRef routingUrl((const char *)r->uri.data, uriLen);
StringRef userAgent;
if (r->headers_in.user_agent)
userAgent = StringRef((const char *)r->headers_in.user_agent->value.data, r->headers_in.user_agent->value.len);
std::string userCookie = ngx_http_get_cookie(r);
std::string lang = ngx_http_get_language(r);
HttpRequest req;
HttpResponse res;
req.SetMethod(kHttp_Method_Get);
req.SetUrl(routingUrl);
req.SetIp(IP);
//req.SetHost(StringRef(host, strlen(host)));
req.SetUserAgent(userAgent);
req.SetUserCookie(StringRef(userCookie.c_str(), userCookie.length()));
req.SetAcceptLanguage(StringRef(lang.c_str(), lang.length()));
req.ParseCookie();
DE.ResponseRequest(req, res);
ngx_str_t k = ngx_string("X-Powered-By");
ngx_str_t v = ngx_string("cxxmvc/0.1");;
ngx_http_add_header(r, &v, &k);
if (res.GetResponseType() == kResponseTypeRedirect)
{
ngx_str_t k = ngx_string("location");
ngx_str_t v = {res.GetContent().length(), (u_char *)res.GetContent().c_str()};
ngx_http_add_header(r, &v, &k);
}
HeaderList headers = res.GetHeaders();
if (headers.size() > 0)
{
HeaderList::iterator iter;
HeaderList::iterator end = headers.end();
for (iter = headers.begin(); iter != end; ++iter)
{
ngx_str_t k;
ngx_str_t v;
k.data = (u_char *)ngx_pcalloc(r->pool, iter->first.length()+1);
k.len = iter->first.length();
strcpy((char *)k.data, (const char *)iter->first.c_str());
v.data = (u_char *)ngx_pcalloc(r->pool, iter->second.length()+1);
v.len = iter->second.length();
strcpy((char *)v.data, (const char *)iter->second.c_str());
// std::cout << "key : "<< k.data << std::endl;
// std::cout << "value : " << v.data << std::endl;
ngx_http_add_header(r, &v, &k);
}
}
CookieList cookies = res.GetCookies();
if (cookies.size() > 0)
{
CookieList::iterator iter;
CookieList::iterator end = cookies.end();
for (iter = cookies.begin(); iter != end; ++iter)
{
ngx_str_t v;
v.data = (u_char *)ngx_pcalloc(r->pool, iter->length()+1);
v.len = iter->length();
strcpy((char *)v.data, (const char *)iter->c_str());
ngx_http_add_cookie(r, v);
}
}
//.........这里部分代码省略.........