if (e == NULL)
return 0;
- return strtoul (e, NULL, 10);
+ return boost::lexical_cast <size_t> (e);
}
int CGIForm::at (const ustring& name, ustring& ans) {
s = std::cin.read (&b[0], s).gcount ();
if (s <= 0)
break;
- s = ::write (fp.fd, &b[0], s);
+ ::write (fp.fd, &b[0], s);
size -= s;
mapsize += s;
- if (size > 0) {
- std::cerr << "post-file[" << mypid << ":" << env->scriptName << "]: reading " << mapsize << "Bytes...\n"; // cerrはバッファリングされない
- }
}
-// fp.close ();
- std::cerr << "post-file[" << mypid << ":" << env->scriptName << "]: done " << mapsize << "Bytes\n";
+// fp.close (); mmapした後にクローズする。
+// std::cerr << "post-file[" << mypid << ":" << env->scriptName << "]: done " << mapsize << "Bytes\n"; // 出力サイズが大きいと、デッドロックする。
mapdata = (char*)mmap (NULL, mapsize, PROT_READ, MAP_PRIVATE, fp.fd, 0);
#ifdef DEBUG2
std::cerr << (void*) mapdata << ": " << mapsize << "\n";
ustring HTTPSendIConv::cv (const ustring& text) {
// 出力側
- return cd_out.cv (text);
+ return cd_out.cv (text, true);
}
ustring HTTPSendIConv::rcv (const ustring& text) {
// 入力側
- return cd_in.cv (text);
+ return cd_in.cv (text, true);
}
return out_toText (str);
}
+MotorOutput* MotorOutputIConv::flush () {
+ ustring o;
+
+ o = cd.cv (uEmpty, true); // flush
+ out (o.data (), o.length ());
+ return this;
+}
+
MotorOutput* MotorOutputIConvOStream::out (const ustring::value_type* s, size_t len) {
std::cout.write (s, len);
return this;
virtual MotorOutput* out_toText (const ustring& str);
virtual MotorOutput* out_templateText (const ustring& str);
+ virtual MotorOutput* flush ();
virtual const ustring charset () {
return code;
};
}
}
-ustring UIConv::cv (const ustring& text) {
+ustring UIConv::cv (const ustring& text, bool flush) {
ustring ans;
if (cd != ICONV_ERR) {
if (obuf > buf)
ans.append (buf, obuf - buf);
}
+ if (flush) {
+ obuf = buf;
+ osize = 4096;
+ rsize = ::iconv (cd, NULL, NULL, &obuf, &osize);
+ if (obuf > buf)
+ ans.append (buf, obuf - buf);
+ }
delete buf;
}
return ans;
}
+///////////////////////////////////////////////////////////////////////
static bool isDigit (int c) {
return '0' <= c && c <= '9';
}
cd = ICONV_ERR;
}
};
- virtual ustring cv (const ustring& text);
+ virtual ustring cv (const ustring& text, bool flush = false);
};
ustring c3 (const ustring& str);
ustring NeonQuery::cv (const ustring& src) {
if (cv_out.get ()) {
- return cv_out->cv (src);
+ return cv_out->cv (src, true);
} else {
return src;
}
ustring NeonQuery::rcv (const ustring& src) {
if (cv_in.get ()) {
- return cv_in->cv (src);
+ return cv_in->cv (src, true);
} else {
return src;
}
motor.compile (text);
motor.output (&out, mlenv->env);
}
+#ifdef UTF8JP
+ out.flush ();
+#endif
SplitterNL sp (out.ans);
line.resize (0);
while (sp.next ()) {
if (readFile (src (param), ans, cPOSTLIMITHARD)) {
if (encoding.size () > 0 && ans.size () > 0) {
UIConv cd (kCODE_UTF8, encoding.c_str ());
- ans = cd.cv (ans);
+ ans = cd.cv (ans, true);
}
ans = fixUTF8 (ans);
}
if (readFile (src, data, cPOSTLIMITHARD)) {
if (encoding.size () > 0 && data.size () > 0) {
UIConv cd (kCODE_UTF8, encoding.c_str ());
- data = cd.cv (data);
+ data = cd.cv (data, true);
}
data = fixUTF8 (data);
return newMNode_str (new ustring (data));
if (encoding.size () > 0 && data.size () > 0) {
UIConv cd (encoding.c_str (), kCODE_UTF8);
- data = cd.cv (data);
+ data = cd.cv (data, true);
}
if (fcrlf)
data = toCRLF (data);