PHP UDP socket_recv()超时(PHP UDP socket_ recv() timeout)
我正在研究可以通过UDP套接字进行通信的服务器/客户端php脚本。 我想知道是否有一种很好的方法来实现socket_recv()函数的timeout() 。 目前它在我的客户端阻塞,等待确认。
感谢您的输入!
I am working on server/client php scripts which can communicate over a UDP socket. I was wondering if there is a good way to implement a timeout() for the socket_recv() function. Currently it is blocking in my client, waiting for an ack.
Thanks for your input!
原文:https://stackoverflow.com/questions/16098026
最满意答案
对此最简单的解决方案是仅定义更改值的数组并使用FactoryGirl步骤中的数组
urls = [nil, "https://www.facebook.com/rihanna/videos/10155221800656676/", ...] xs = [nil, 500, ...] ys = [nil, 200, ...] (0..4).each do |n| let!(:"deal1_step#{n}") { FactoryGirl.create(:step, video_url: urls[n], video_x: xs[n], video_y: ys[n], st_background_asset_filename: "campaigns/042017/assets_for_tests_and_dev/backgroundimage#{n}.jpg", deal: deal1) } end
对于其他任何事情你需要了解
let
/let!
作品。let
在示例中定义一个方法(由传入的符号命名)(它实际上在混合的模块上,效果相同),它会记忆传递给它的块的响应。let!
调用let
然后定义一个调用方法let
的前块,以便在测试示例之前运行它。 这就是为什么你得到错误'deal1_step1
在示例组上不可用(例如......),因为该方法是在示例上定义的,而不是在组上。因此,如果您不想执行上面的数组示例之类的操作,那么您需要在一个在示例上下文中运行的块中进行属性更新,因此
before
块before
- 就像(0..4).each do |n| let!(:"deal1_step#{n}") { FactoryGirl.create(:step, order_nb: n, message_content: "this is message #{n}", background_asset_filename: "campaigns/assets_for_tests/backgroundimage#{n}.jpg", deal: deal) } end before do deal1_step1.video_url = "https://www.facebook.com/rihanna/videos/10155221800656676/" deal1_step1.video_x = 500 deal1_step1.video_y = 500 # may need to save deal1_step1 depending on exactly what you're looking for deal1_step2.update_attributes(video_url: "https://www.facebook.com/rihanna/videos/10155221800656676/", video_x: 500, video_y: 500 ) ... end
The easiest solution to this is to just define arrays of the changing values and use those in your FactoryGirl steps
urls = [nil, "https://www.facebook.com/rihanna/videos/10155221800656676/", ...] xs = [nil, 500, ...] ys = [nil, 200, ...] (0..4).each do |n| let!(:"deal1_step#{n}") { FactoryGirl.create(:step, video_url: urls[n], video_x: xs[n], video_y: ys[n], st_background_asset_filename: "campaigns/042017/assets_for_tests_and_dev/backgroundimage#{n}.jpg", deal: deal1) } end
For anything else you need to understand how
let
/let!
works.let
defines a method (named by the symbol passed in) on the example (it's actually on a module that gets mixed in, same effect) which memoizes the response of the block passed to it.let!
callslet
and then defines a before block that calls the methodlet
defined so it has already been run before the test example is. That's why you're getting the error 'deal1_step1
is not available on an example group (e.g. a ...', because the method is defined on the example, not on the group.Therefore, if you don't want to do something like the arrays example above then you'd need to do your attribute updating in a block that gets run in the example context, so a
before
block - like(0..4).each do |n| let!(:"deal1_step#{n}") { FactoryGirl.create(:step, order_nb: n, message_content: "this is message #{n}", background_asset_filename: "campaigns/assets_for_tests/backgroundimage#{n}.jpg", deal: deal) } end before do deal1_step1.video_url = "https://www.facebook.com/rihanna/videos/10155221800656676/" deal1_step1.video_x = 500 deal1_step1.video_y = 500 # may need to save deal1_step1 depending on exactly what you're looking for deal1_step2.update_attributes(video_url: "https://www.facebook.com/rihanna/videos/10155221800656676/", video_x: 500, video_y: 500 ) ... end
相关问答
更多-
这对我的设计有用: 我更改了users / registrations_controller.rb class Users::RegistrationsController < Devise::RegistrationsController before_action :configure_permitted_parameters, only: [:create] before_filter :configure_account_update_params, only: [:update] d ...
-
对此最简单的解决方案是仅定义更改值的数组并使用FactoryGirl步骤中的数组 urls = [nil, "https://www.facebook.com/rihanna/videos/10155221800656676/", ...] xs = [nil, 500, ...] ys = [nil, 200, ...] (0..4).each do |n| let!(:"deal1_step#{n}") { FactoryGirl.create(:step, video_url: ...
-
Rails 4.2中的连接范围(Scope with joins in Rails 4.2)[2023-05-03]
范围主体需要可调用。 (引发ArgumentError) 这应该工作 scope :with_comments, -> { joins(:comments) } 这里有个很好的解释 The scope body needs to be callable. (ArgumentError) This should work scope :with_comments, -> { joins(:comments) } A nice explanation here -
Rails 4.2 - 最后一条记录的#created_at是否超过1天?(Rails 4.2 - Is the last record's #created_at more than 1 day old?)[2023-06-04]
简单的self.personal_care_forms.last.created_at < 1.day.ago应该在控制台和应用程序中工作和行为相同。 尝试将日志添加到您的Resident类中(注意我也折叠了布尔返回)并查看您获得的内容: class Resident < ActiveRecord::Base . . . def medical_record_expired? puts "created_at: #{medical_record_forms.last.created_ ... -
Rails Factory Girl:创建与用户相关但具有角色的记录(Rails Factory Girl: Create record associated with user but with role)[2021-09-10]
您始终可以通过将字段传递给build或create方法来覆盖字段。 要将event_operator设置为所需的user ,您可以这样做: user = build(:user) event = build(:event, event_operator: user) You can always override fields by passing them to the build or create methods. To set event_operator to your desired user ... -
它看起来不像你正在初始化@price ,这就是你收到错误的原因。 尝试: def destroy @price = Price.find(params[:id]) @price.destroy ... end 您还需要在show初始化@price并update操作。 It doesn't look like you're initializing @price, which is why you're getting the error. Try: def destroy @price = ...
-
这是你的工厂: factories/users.rb FactoryBot.define do factory :user do sequence(:email) { |n| "abc#{n}@example.com" } password { 'password' } password_confirmation { 'password' } end end 然后你可以写规格 describe User, type: :model do describe 'some b ...
-
第1部分 即使该功能已弃用,您仍然可以使用此功能。 用你想要做的几件事在这里可能会有用。 class Hash def diff h2 self.dup.delete_if { |k, v| h2[k] == v }.merge(h2.dup.delete_if { |k, v| self.has_key?(k) }) end def only *args h = {} args.each do |a| h[a] = self[a] end ...
-
Rails 4.2和postgres - 无法更新属性,可能的原因?(Rails 4.2 and postgres - cannot update an attribute, possible reasons?)[2023-01-10]
所以你看到一个UPDATE查询,但记录没有发生变化? 检查ROLLBACK - 如果我不得不猜测我会说验证失败了。 也许尝试update_attributes !,如果记录无效,将抛出异常。 So I have found the source of the problem (but not the error) - migration files were different for Hotels and Restaurants. Hotels used migration using method ch ... -
这最终成为我的HAML模板的问题: %h2= pluralize(@families.length, 'Adopting family') 这条线试图count @families ivar,这导致一些问题与Kaminari和加入。 当我评论出这条线路时,它运行得很好,但我仍然希望显示找到了多少搜索结果。 所以我只是将count改为length而且效果很好。 This ended up being a problem w/ my HAML template: %h2= pluralize(@familie ...