diff options
author | Ryan Bloom <rbb@apache.org> | 2004-03-13 12:34:49 +0000 |
---|---|---|
committer | Ryan Bloom <rbb@apache.org> | 2004-03-13 12:34:49 +0000 |
commit | 9304e1c25601ca149b21758a197fb39bbbe58b9e (patch) | |
tree | c35166e1e62e8398120a3f285949a2be4b099d81 /test/tryread.c | |
parent | e26f44996391906644b29dd6e89f4aca1154c06f (diff) | |
download | apr-9304e1c25601ca149b21758a197fb39bbbe58b9e.tar.gz |
Migrate testflock to unified test framework
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64977 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/tryread.c')
-rw-r--r-- | test/tryread.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/tryread.c b/test/tryread.c new file mode 100644 index 000000000..d60b942cb --- /dev/null +++ b/test/tryread.c @@ -0,0 +1,62 @@ +/* Copyright 2000-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * USAGE + * + * Start one process, no args, and place it into the background. Start a + * second process with the "-r" switch to attempt a read on the file + * created by the first process. + * + * $ ./testflock & + * ...messages... + * $ ./testflock -r + * ...messages... + * + * The first process will sleep for 30 seconds while holding a lock. The + * second process will attempt to grab it (non-blocking) and fail. It + * will then grab it with a blocking scheme. When the first process' 30 + * seconds are up, it will exit (thus releasing its lock). The second + * process will acquire the lock, then exit. + */ + +#include "testflock.h" +#include "apr_pools.h" +#include "apr_file_io.h" +#include "apr_general.h" + +int main(int argc, const char * const *argv) +{ + apr_file_t *file; + apr_status_t status; + apr_pool_t *p; + + apr_initialize(); + apr_pool_create(&p, NULL); + + if (apr_file_open(&file, TESTFILE, APR_WRITE, APR_OS_DEFAULT, p) + != APR_SUCCESS) { + + exit(UNEXPECTED_ERROR); + } + status = apr_file_lock(file, APR_FLOCK_EXCLUSIVE | APR_FLOCK_NONBLOCK); + if (status == APR_SUCCESS) { + exit(SUCCESSFUL_READ); + } + if (APR_STATUS_IS_EAGAIN(status)) { + exit(FAILED_READ); + } + exit(UNEXPECTED_ERROR); +} |