⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apr::bucket.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 2 页
字号:
.IX Subsection "is_flush"Determine if a bucket is a \s-1FLUSH\s0 bucket.PP.Vb 1\&  $ret = $bucket\->is_flush();.Ve.ie n .IP "obj: $bucket\fR ( \f(CW""APR::Bucket object"" )" 4.el .IP "obj: \f(CW$bucket\fR ( \f(CWAPR::Bucket object\fR )" 4.IX Item "obj: $bucket ( APR::Bucket object )".PD 0.ie n .IP "ret: $ret ( boolean )" 4.el .IP "ret: \f(CW$ret\fR ( boolean )" 4.IX Item "ret: $ret ( boolean )".IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PD.ie n .Sh """length""".el .Sh "\f(CWlength\fP".IX Subsection "length"Get the length of the data in the bucket..PP.Vb 1\&  $len = $b\->length;.Ve.ie n .IP "obj: $b\fR ( \f(CW""APR::Bucket object"" )" 4.el .IP "obj: \f(CW$b\fR ( \f(CWAPR::Bucket object\fR )" 4.IX Item "obj: $b ( APR::Bucket object )".PD 0.ie n .IP "ret: $len ( integer )" 4.el .IP "ret: \f(CW$len\fR ( integer )" 4.IX Item "ret: $len ( integer )".PDIf the length is unknown, \f(CW$len\fR value will be \-1..IP "since: 2.0.00" 4.IX Item "since: 2.0.00".ie n .Sh """new""".el .Sh "\f(CWnew\fP".IX Subsection "new"Create a new bucket and initialize it with data:.PP.Vb 4\&  $nb = APR::Bucket\->new($ba, $data);\&  $nb =          $b\->new($ba, $data);\&  $nb = APR::Bucket\->new($ba, $data, $offset);\&  $nb = APR::Bucket\->new($ba, $data, $offset, $len);.Ve.ie n .IP "obj: $b\fR ( \f(CW""APR::Bucket object or class"" )" 4.el .IP "obj: \f(CW$b\fR ( \f(CWAPR::Bucket object or class\fR )" 4.IX Item "obj: $b ( APR::Bucket object or class )".PD 0.ie n .IP "arg1: $ba\fR ( \f(CW""APR::BucketAlloc object"" )" 4.el .IP "arg1: \f(CW$ba\fR ( \f(CWAPR::BucketAlloc object\fR )" 4.IX Item "arg1: $ba ( APR::BucketAlloc object )".ie n .IP "arg2: $data ( string )" 4.el .IP "arg2: \f(CW$data\fR ( string )" 4.IX Item "arg2: $data ( string )".PDThe data to initialize with..Sp\&\fBImportant:\fR in order to avoid unnecessary data copying the variableis stored in the bucket object. That means that if you modify \f(CW$data\fRafter passing it to \f(CW\*(C`new()\*(C'\fR you will modify the data in the bucket aswell. To avoid that pass to \f(CW\*(C`new()\*(C'\fR a copy which you won't modify..ie n .IP "opt arg3: $offset ( number )" 4.el .IP "opt arg3: \f(CW$offset\fR ( number )" 4.IX Item "opt arg3: $offset ( number )"Optional offset inside \f(CW$data\fR. Default: 0..ie n .IP "opt arg4: $len ( number )" 4.el .IP "opt arg4: \f(CW$len\fR ( number )" 4.IX Item "opt arg4: $len ( number )"Optional partial length to read..SpIf \f(CW$offset\fR is specified, then:.Sp.Vb 1\&  length $buffer \- $offset;.Ve.Spwill be used. Otherwise the default is to use:.Sp.Vb 1\&  length $buffer;.Ve.ie n .IP "ret: $nb\fR ( \f(CW""APR::Bucket object"" )" 4.el .IP "ret: \f(CW$nb\fR ( \f(CWAPR::Bucket object\fR )" 4.IX Item "ret: $nb ( APR::Bucket object )"a newly created bucket object.IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PPExamples:.IP "\(bu" 4Create a new bucket using a whole string:.Sp.Vb 3\&  use APR::Bucket ();\&  my $data = "my data";\&  my $b = APR::Bucket\->new($ba, $data);.Ve.Spnow the bucket contains the string \fI'my data'\fR..IP "\(bu" 4Create a new bucket using a sub-string:.Sp.Vb 4\&  use APR::Bucket ();\&  my $data   = "my data";\&  my $offset = 3;\&  my $b = APR::Bucket\->new($ba, $data, $offset);.Ve.Spnow the bucket contains the string \fI'data'\fR..IP "\(bu" 4Create a new bucket not using the whole length and starting from anoffset:.Sp.Vb 5\&  use APR::Bucket ();\&  my $data   = "my data";\&  my $offset = 3;\&  my $len    = 3;\&  my $b = APR::Bucket\->new($ba, $data, $offset, $len);.Ve.Spnow the bucket contains the string \fI'dat'\fR..ie n .Sh """read""".el .Sh "\f(CWread\fP".IX Subsection "read"Read the data from the bucket..PP.Vb 2\&  $len = $b\->read($buffer);\&  $len = $b\->read($buffer, $block);.Ve.ie n .IP "obj: $b\fR ( \f(CW""APR::Bucket object"" )" 4.el .IP "obj: \f(CW$b\fR ( \f(CWAPR::Bucket object\fR )" 4.IX Item "obj: $b ( APR::Bucket object )"The bucket to read from.ie n .IP "arg1: $buffer ( \s-1SCALAR\s0 )" 4.el .IP "arg1: \f(CW$buffer\fR ( \s-1SCALAR\s0 )" 4.IX Item "arg1: $buffer ( SCALAR )"The buffer to fill. All previous data will be lost..ie n .IP "opt arg2: $block\fR ( \f(CW""APR::Const :read_type constant"" )" 4.el .IP "opt arg2: \f(CW$block\fR ( \f(CWAPR::Const :read_type constant\fR )" 4.IX Item "opt arg2: $block ( APR::Const :read_type constant )"optional reading mode constant..SpBy default the read is blocking, via \f(CW\*(C`APR::Const::BLOCK_READconstant\*(C'\fR..ie n .IP "ret: $len ( number )" 4.el .IP "ret: \f(CW$len\fR ( number )" 4.IX Item "ret: $len ( number )"How many bytes were actually read.Sp\&\f(CW$buffer\fR gets populated with the string that is read. It willcontain an empty string if there was nothing to read..IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PD 0.ie n .IP "excpt: ""APR::Error""" 4.el .IP "excpt: \f(CWAPR::Error\fR" 4.IX Item "excpt: APR::Error".PD.PPIt's important to know that certain bucket types (e.g. file bucket),may perform a split and insert extra buckets following the currentone. Therefore never call \f(CW\*(C`$b\->remove\*(C'\fR, beforecalling \f(CW\*(C`$b\->read\*(C'\fR, or you may lose data..PPExamples:.PPBlocking read:.PP.Vb 1\&  my $len = $b\->read(my $buffer);.Ve.PPNon-blocking read:.PP.Vb 2\&  use APR::Const \-compile \*(AqNONBLOCK_READ\*(Aq;\&  my $len = $b\->read(my $buffer, APR::Const::NONBLOCK_READ);.Ve.ie n .Sh """remove""".el .Sh "\f(CWremove\fP".IX Subsection "remove"Tell the bucket to remove itself from the bucket brigade it belongsto..PP.Vb 1\&  $bucket\->remove();.Ve.ie n .IP "obj: $bucket\fR ( \f(CW""APR::Bucket object"" )" 4.el .IP "obj: \f(CW$bucket\fR ( \f(CWAPR::Bucket object\fR )" 4.IX Item "obj: $bucket ( APR::Bucket object )".PD 0.IP "ret: no return value" 4.IX Item "ret: no return value".IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PD.PPIf the bucket is not attached to any bucket brigade then thisoperation doesn't do anything..PPWhen the bucket is removed, it's not not destroyed. Usually this isdone in order to move the bucket to another bucket brigade. Or to copythe data way before destroying the bucket.  If the bucket wasn't movedto another bucket brigade it must be destroyed..PPExamples:.PPAssuming that \f(CW$bb1\fR already exists and filled with buckets, moveevery odd bucket number to \f(CW$bb2\fR and every even to \f(CW$bb3\fR:.PP.Vb 10\&  my $bb2 = APR::Brigade\->new($c\->pool, $c\->bucket_alloc);\&  my $bb3 = APR::Brigade\->new($c\->pool, $c\->bucket_alloc);\&  my $count = 0;\&  while (my $bucket = $bb\->first) {\&      $count++;\&      $bucket\->remove;\&      $count % 2\&          ? $bb2\->insert_tail($bucket)\&          : $bb3\->insert_tail($bucket);\&  }.Ve.ie n .Sh """setaside""".el .Sh "\f(CWsetaside\fP".IX Subsection "setaside"Ensure the bucket's data lasts at least as long as the given pool:.PP.Vb 1\&  my $status = $b\->setaside($pool);.Ve.ie n .IP "obj: $b\fR ( \f(CW""APR::Bucket object"" )" 4.el .IP "obj: \f(CW$b\fR ( \f(CWAPR::Bucket object\fR )" 4.IX Item "obj: $b ( APR::Bucket object )".PD 0.ie n .IP "arg1: $pool\fR ( \f(CW""APR::Pool object"" )" 4.el .IP "arg1: \f(CW$pool\fR ( \f(CWAPR::Pool object\fR )" 4.IX Item "arg1: $pool ( APR::Pool object )".ie n .IP "ret: ( ""APR::Const status constant"" )" 4.el .IP "ret: ( \f(CWAPR::Const status constant\fR )" 4.IX Item "ret: ( APR::Const status constant )".PDOn success,\&\f(CW\*(C`APR::Const::SUCCESS\*(C'\fR isreturned. Otherwise a failure code is returned..ie n .IP "excpt: ""APR::Error""" 4.el .IP "excpt: \f(CWAPR::Error\fR" 4.IX Item "excpt: APR::Error"when your code deals only with mod_perl buckets, you don't have to askfor the return value. If this method is called in the \f(CW\*(C`VOID\*(C'\fR context,i.e.:.Sp.Vb 1\&  $b\->setaside($pool);.Ve.Spmod_perl will do the error checking on your behalf, and if the returncode is not\&\f(CW\*(C`APR::Const::SUCCESS\*(C'\fR, an\&\f(CW\*(C`APR::Error exception\*(C'\fR will be thrown..SpHowever if your code doesn't know which bucket types it may need tosetaside, you may want to check the return code and deal with anyerrors. For example one of the possible error codes is\&\f(CW\*(C`APR::Const::ENOTIMPL\*(C'\fR. As ofthis writing the pipe and socket buckets can't \f(CW\*(C`setaside()\*(C'\fR, in whichcase you may want to look at the \f(CW\*(C`ap_save_brigade()\*(C'\fR implementation..IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PPUsually setaside is called by certain output filters, in order tobuffer socket writes of smaller buckets into a single write. Thismethod works on all bucket types (not only the mod_perl bucket type),but as explained in the exceptions section, not all bucket typesimplement this method..PPWhen a mod_perl bucket is setaside, its data is detached from theoriginal perl scalar and copied into a pool bucket. That allowsdownstream filters to deal with the data originally owned by a Perlinterpreter, making it possible for that interpreter to go away and doother things, or be destroyed..ie n .Sh """type""".el .Sh "\f(CWtype\fP".IX Subsection "type"Get the type of the data in the bucket..PP.Vb 1\&  $type = $b\->type;.Ve.ie n .IP "obj: $b\fR ( \f(CW""APR::Bucket object"" )" 4.el .IP "obj: \f(CW$b\fR ( \f(CWAPR::Bucket object\fR )" 4.IX Item "obj: $b ( APR::Bucket object )".PD 0.ie n .IP "ret: $type\fR ( \f(CW""APR::BucketType object"" )" 4.el .IP "ret: \f(CW$type\fR ( \f(CWAPR::BucketType object\fR )" 4.IX Item "ret: $type ( APR::BucketType object )".IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PD.PPYou need to invoke\&\f(CW\*(C`APR::BucketType\*(C'\fR methods toaccess the data..PPExample:.PPCreate a flush bucket and read its type's name:.PP.Vb 5\&  use APR::Bucket ();\&  use APR::BucketType ();\&  my $b = APR::Bucket::flush_create($ba);\&  my $type = $b\->type;\&  my $type_name =  $type\->name; # FLUSH.Ve.PPThe type name will be \fI'\s-1FLUSH\s0'\fR in this example..SH "Unsupported API".IX Header "Unsupported API"\&\f(CW\*(C`APR::Socket\*(C'\fR also provides auto-generated Perl interface for a fewother methods which aren't tested at the moment and therefore their\&\s-1API\s0 is a subject to change. These methods will be finalized later as aneed arises. If you want to rely on any of the following methodsplease contact the the mod_perl development mailinglist so we can help each other take the steps necessaryto shift the method to an officially supported \s-1API\s0..ie n .Sh """data""".el .Sh "\f(CWdata\fP".IX Subsection "data".Vb 1\&  $data = $b\->data;.Ve.PPGives a C pointer to the address of the data in the bucket. I can'tsee what use can be done of it in Perl..ie n .IP "obj: $b\fR ( \f(CW""APR::Bucket object"" )" 4.el .IP "obj: \f(CW$b\fR ( \f(CWAPR::Bucket object\fR )" 4.IX Item "obj: $b ( APR::Bucket object )".PD 0.ie n .IP "ret: $data ( C pointer )" 4.el .IP "ret: \f(CW$data\fR ( C pointer )" 4.IX Item "ret: $data ( C pointer )".IP "since: subject to change" 4.IX Item "since: subject to change".PD.ie n .Sh """start""".el .Sh "\f(CWstart\fP".IX Subsection "start".Vb 1\&  $start = $b\->start;.Ve.PPIt gives the offset to when a new bucket is created with a non-zerooffset value:.PP.Vb 1\&  my $b = APR::Bucket\->new($ba, $data, $offset, $len);.Ve.PPSo if the offset was 3. \f(CW$start\fR will be 3 too..PPI fail to see what it can be useful for to the end user (it's mainlyused internally)..ie n .IP "obj: $b\fR ( \f(CW""APR::Bucket object"" )" 4.el .IP "obj: \f(CW$b\fR ( \f(CWAPR::Bucket object\fR )" 4.IX Item "obj: $b ( APR::Bucket object )".PD 0.ie n .IP "ret: $start ( offset number )" 4.el .IP "ret: \f(CW$start\fR ( offset number )" 4.IX Item "ret: $start ( offset number )".IP "since: subject to change" 4.IX Item "since: subject to change".PD.SH "See Also".IX Header "See Also"mod_perl 2.0 documentation..SH "Copyright".IX Header "Copyright"mod_perl 2.0 and its core modules are copyrighted underThe Apache Software License, Version 2.0..SH "Authors".IX Header "Authors"The mod_perl development team and numerouscontributors.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -